# Finding the largest square factor of an integer without complete factorization [duplicate]

When faced with the problem of reducing a fraction to lowest terms, it appears that currently conventional textbooks say one should do something like this: $$\frac{408}{684} = \frac{2\times2\times2\times3\times17}{2\times2\times3\times3\times 19} = \frac{17}{19},$$ i.e. factor both the numerator and the denominator and then cancel.

(But maybe I'm mistaken as to what the most up-to-date textbooks say.)

This becomes somewhat more onerous with things like $\dfrac{49494}{21583}.$ And considerably more onerous in some other cases whose details I leave for now to the reader's imagination.

$$\frac{49494}{21583} = \frac{2\times3\times73\times113}{113\times191} = \frac{438}{191}.$$ Finding the prime factors in a case like $113\times191$

But Euclid's algorithm, introduced around 300 BC and thus the oldest algorithm still in standard use today, tells us that \begin{align} & \gcd(49494,21583) = \gcd(6328,21583) = \gcd(6328,2599) \\[10pt] = {} & \gcd(1130,2599) = \gcd(1130,339) = \gcd(113,339) = \gcd(113,0) = 113, \end{align} so that $$\frac{49494}{21583} = \frac{113\times438}{113\times191}.$$ No need to search for prime factors. Divisiblity of the numerator by $73$ is irrelevant to the problem and isn't hinted at by Euclid's algorithm.

So my question involves another problem for which complete factorization seems to be the standard recommended method: $$\sqrt{4536} = \sqrt{2\times2\times2\times3\times3\times3\times3\times7} = 2\times3\times3\times\sqrt{2\times7} = 18\sqrt{14}.$$

What about things like $\displaystyle\sqrt{159501017} = \sqrt{13\times13\times83\times83\times137}\text{ ?}$

An efficient algorithm for finding the greatest square factor would tell us that it is $1164241 = (1079)^2$ without bringing in the irrelevant divisibility of that number by $13$ and $83.$ Is there such an algorithm?

## marked as duplicate by ccorn, Robert Soupe, user91500, Dando18, NamasteSep 4 '17 at 17:12

• No, even the decision whether a number is squarfree is asymptotically as difficult as the complete factorization, this is at least the current status. Small squares can easily be detected by trial division, for example, but a number of the form $p^2\cdot q$, where $p$ and $q$ are distinct primes of, lets say, $500$ digits from which we do not know the factors and even that it is squarefree, we will not be able to decide whether it is squarefree with reasonable effort. – Peter Aug 28 '17 at 22:45
• In practice, we can be relatively sure that the number $n$ is squarefree if we do not find a prime factor $p\le 10^9$ with $p^2|n$, but this is of course no guarantee. – Peter Aug 28 '17 at 22:50
here's my answer, expanding a bit on what Peter said in the comments, and showing you why it is not irrelevant that 13 and 83 divide your example. No there is not really a more efficient algorithm known. We can know things like if a number could be a perfect square fairly simply ( just test if it's 0, 1, or 4 mod 8. if not it's not a square of an integer), the problem is any square we find is divisible by the prime squares dividing the number in question (so it's because $a^2b^2=(ab)^2$, that your prime factors aren't irrelevant). That being said not all numbers having the remainder mod 8 of a square, will be a square. we have necessary conditions but not very useful sufficient ones to prove a number is/is not a squarefree number.