Ma · Mathematics

How to Analyze Whether an Integer Is a Perfect Square

Published By the 9to5Science editorial team

At a glance

  1. 1. Check the domain

    A perfect square is an integer of the form m²; negative integers are not squares of integers.

  2. 2. Use factorization

    A positive integer is a square exactly when every exponent in its prime factorization is even.

  3. 3. Apply residue tests

    Reject numbers whose remainders are not possible square remainders modulo a small integer.

  4. 4. Verify exactly

    Compute the integer square root and check whether its square equals the number.

If by analyzing a number you mean deciding whether it is a perfect square, the key is to distinguish quick tests from proofs. A remainder test can show that a number is not a square, while prime factorization or an exact integer-square-root check can confirm whether it is one.

Here, a perfect square means the square of an integer. Thus nn is a perfect square if n=m2n=m^2 for some integer mm. Zero is a perfect square because 0=020=0^2; negative integers are not squares of integers.

Use prime factorization for an exact criterion

Write a positive integer as a product of primes. The number is a perfect square exactly when each prime has an even exponent:

n=p1e1p2e2⋯pkekn=p_1^{e_1}p_2^{e_2}\cdots p_k^{e_k}

is a square if and only if every eie_i is even. If all exponents are even, take half of each exponent to obtain the square root:

n=p1e1/2p2e2/2⋯pkek/2.\sqrt{n}=p_1^{e_1/2}p_2^{e_2/2}\cdots p_k^{e_k/2}.

This follows because squaring a prime factorization doubles every exponent. Conversely, if n=m2n=m^2, the prime factorization of m2m^2 has twice the exponents in the factorization of mm, so they are all even.

Worked example: 2025

Factor 2025:

2025=452=(32⋅5)2=34⋅52.2025=45^2=(3^2\cdot 5)^2=3^4\cdot 5^2.

Both exponents are even, so 2025 is a perfect square, and its square root is 32⋅5=453^2\cdot5=45.

For a contrasting example, 72=23⋅3272=2^3\cdot3^2. The exponent of 2 is odd, so 72 is not a perfect square.

Use modular arithmetic to rule out candidates

A square can have only certain remainders when divided by a fixed integer. For example, the possible square remainders modulo 16 are

0,1,4,9.0,1,4,9.

So if an integer leaves remainder 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, or 15 upon division by 16, it cannot be a square. The same idea works modulo other numbers. Modulo 4, for instance, a square is congruent only to 0 or 1.

A remainder test is a necessary condition, not usually a sufficient one. For example, 73 leaves remainder 9 modulo 16 and remainder 1 modulo 3, both possible square remainders. Yet 73 is not a square: it lies between 82=648^2=64 and 92=819^2=81.

Digit tests are a special case of modular reasoning. In base 10, a square can end only in 0, 1, 4, 5, 6, or 9. If a number ends in 2, 3, 7, or 8, it is immediately ruled out. But an allowed final digit does not establish that the whole number is square.

Check with an integer square root

For a large number, you do not need to factor it completely. Find the integer square root r=⌊n⌋r=\lfloor\sqrt n\rfloor, the greatest integer whose square is at most nn. Then nn is a perfect square exactly when r2=nr^2=n.

For example, to test 2026, note that 452=202545^2=2025 and 462=211646^2=2116. Therefore 2025<2026<21162025<2026<2116, so 2026 is not a square. This also shows why checking nearby consecutive squares can be more efficient than factoring.

On a computer, use an integer-square-root operation when available, then compare its square with the original integer. Avoid relying only on a floating-point square root for very large integers: rounding can make a near-integer result misleading. Exact integer arithmetic avoids that issue.

Common mistakes

  • Treating a possible last digit as proof. Ending in 0, 1, 4, 5, 6, or 9 is compatible with being a square, but many numbers with those endings are not squares.
  • Forgetting the exponents in factorization. A number is square only if every prime exponent is even; being divisible by a square is not enough.
  • Using an approximate square root as an exact test. Check the integer square or compare with neighboring squares.
  • Including negative integers under the integer definition. A negative number has no integer square root. In the real numbers, it also has no real square root.

For a quick hand analysis, use a small-modulus test first to eliminate impossible cases, then compare with nearby consecutive squares. For a proof or an exact classification, use the even-exponent criterion or verify the integer square root.

References

  1. David M. Burton, Elementary Number Theory

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.