Hello, I recently bought a TI-Nspire CX calculator, and i was wondering what the syntax for Simplest Radical From is, so I can write a program to simplify radicals. The Language is quite easy, and if you could give me the C++ equivalent, I should be able to translate it.
int x = 12;
int cx = x;
int counter = 0;
int a = 1, b;
for( int i = 2; i < x; ) {
if( x % i == 0 ) {
counter ++;
x /= i;
if( counter == 2 ) {
a *= i;
counter = 0;
}
} else {
counter = 0;
i++;
}
}
b = cx/(a*a);
This is for square roots. sqrt(x) is simplified to a*sqrt(b). The idea is to find all prime factors and check if any of them are repeated twice. In that case, you'd multiply a by that factor. b can be computed later.
If you want this to work for nth degree root, replace "counter == 2" with "counter == n" and "b = cx/(a*a)" with "b = cx/prod" where prod is an, computed in a for loop.