← LibraryInteger Square Root and Perfect Power DetectionEngineering · MathematicsLesson 214/385← PrevNext →
ArticlePublished 7 Aug 20262 min readBy Kevin Jogininteger square rootperfect powerNewton iterationpreprocessing

Multiprecision Arithmetic

Integer Square Root and Perfect Power Detection

Newton iteration for integer square roots, exact perfect power detection, and why these cheap tests belong at the front of every factoring routine.

Engineering / MathematicsMultiprecision Arithmetic2 min readKV-MATH-0512

Integer square root and perfect power detection are cheap, exact and easy to get subtly wrong. They belong at the front of any factoring pipeline, because a perfect power that reaches the sieving stage wastes an enormous amount of work.

Integer square root by Newton iteration

The integer square root of N is the largest integer whose square does not exceed N. Newton's method converges quadratically and, with care, terminates exactly.

x_{k+1} = floor( (x_k + floor(N / x_k)) / 2 )Started from an over-estimate, the sequence decreases to the answer.

Integer square root

  1. Initial estimateUse the bit length: start from a power of two just above the true root.
  2. IterateApply the update until the sequence stops decreasing.
  3. VerifyCheck the square against N and adjust by one if needed.

Perfect power detection

A number is a perfect power if it equals m^k for integers with k > 1. Only prime exponents need testing, and only up to the bit length of N, since 2^k must not exceed N.

Perfect power detection

  1. Bound the exponentOnly prime k up to log2(N) can occur.
  2. Estimate the rootCompute an approximate k-th root using floating point on the logarithm.
  3. RefineApply Newton iteration in integers to get an exact candidate.
  4. Verify exactlyRaise the candidate to the k-th power and compare. Floating point is used only to locate the candidate, never to decide.

Why it matters for factoring

Perfect powers must be removed before general factoring
MethodBehaviour on a perfect power
Pollard rhoCan cycle without splitting
Quadratic sieveRelation collection degenerates
ECMWorks but wastes effort rediscovering the same factor
Fermat-style methodsMay fail to separate repeated factors

Related uses

Integer square root also appears directly in SQUFOF, in continued fraction expansion of quadratic irrationals, and in bounding loops for form reduction.

Source. Henri Cohen, A Course in Computational Algebraic Number Theory, Springer GTM 138 — 1.7. Structural reference unverified: the source file was not available during authoring; chapter and section numbers are taken from the published edition and have not been checked against a physical copy.

Continue learning

Binary Powering and Exponentiation ChainsArticle · MathematicsNEXT LESSON →The Euclidean Algorithm: Classical and Binary VariantsArticle · MathematicsModular Arithmetic and Montgomery ReductionArticle · MathematicsLehmer's Accelerated GCD ComputationArticle · Mathematics