Find the largest possible root of a number that is whole

872 Views Asked by At

Using 8 as an example radicand, the degree would be 3 because ∜8 is not a whole number, while √8 is not the largest possible whole root. This type of problem is easy to calculate mentally with small numbers, but for large numbers it gets tricky. Is there a way to calculate it without iterating through degrees until the right one is found? It seems the answers may involve logarithms.

Thanks in advance.

3

There are 3 best solutions below

0
On BEST ANSWER

If you can find the prime factorization of the number, take the greatest common divisor of all the exponents in it.

Unfortunately factoring large numbers is not quick, so simply checking all possible degrees up to $\log_2$ of the number might well be faster asymptotically.

For most inputs, a combination might be the best strategy -- look for small prime factors, and take the gcd of their exponents. Then you only need to check degrees that are factors of that gcd.

0
On

If $a$ has prime factorization $$ a = \prod_{k=1}^n p_k^{e_k} \text{ where } e_k \in \mathbb{N}, p_k \text{ prime} $$ then $$ \sqrt[n]{a} \in \mathbb{N} \text{ exactly if $n \mid e_k$ for all $k$, meaning if } n \mid \textrm{gcd}(e_1,\ldots,d_k). $$ The largest such $n$ is thus $\textrm{gcd}(e_1,\ldots,d_k)$.

0
On

This paper of Daniel J. Bernstein, “Detecting Perfect Powers in Essentially Linear Time” describes a fast algorithm which does exactly what you asked for: given a positive integer $n$, it finds positive integers $x$ and $k$ with $n = x^k$ and $k$ as large as possible. It does so in an amount of time that is (almost) proportional to the number of digits in $n$, which is almost as fast as one could hope for.

Note that this does not require factoring $n$, which would take much longer.