How to efficiently find the largest perfect square dividing a given large integer?

544 Views Asked by At

Given a number $n$. I need to find the largest $q$ such that $q^2$ divides $n$. I need the fastest method to find $q$. $q$ can be any number prime or composite.

At present I am factorizing the number $n$ to find the highest number $q$. I need a better approach which does not involve to factorize the number $n$ completely or by some other approach which is less than $O(\sqrt n)$. Constraint: $n\leq 10^{18}$

some test cases:

  • if $n=180$ then $q=6$
  • if $n=17$ then $q=1$
  • if $n=10000$ then $q=100$
1

There are 1 best solutions below

0
On

It is trivial to to compute square/squarefree parts if we are given the prime factorization. Currently we do not know any better way, and it is widely suspected that there is none, i.e the problem may prove to be equivalent to factorization.

This problem is important because one of the main tasks of computational algebraic number theory reduces to it (in deterministic polynomial time). Namely the problem of computing the ring of integers of an algebraic number field depends upon the square-free decomposition of the polynomial discriminant (when computing an integral basis).

Contrast this difficulty with the trivial squarefree decomposition of polynomials by way of gcd with its derivative. The availability of derivatives for polynomials opens up a powerful toolbox that is not available for integers. For example once derivatives are available so are Wronskians - which provide powerful measures of dependence in transcendence theory and diophantine approximation. A simple yet stunning example is the elementary proof of Mason's ABC theorem for polynomials, which yields as a very special case a high-school-level proof of FLT for polynomials.

For references see my post here.