Skip to main content

How to check if a number is a Perfect Square

Squares of all integers are known as perfect squares. In this lesson, we will discuss a very interesting Mathematical shortcut: How to check whether a number is a perfect square or not. There are some properties of perfect squares which can be used to test if a number is a perfect square or not. They can definitely say if it is not the square. (i.e. Converse is not necessarily true).

All perfect squares end in 1, 4, 5, 6, 9 or 00 (i.e. Even number of zeros). Therefore, a number that ends in 2, 3, 7 or 8 is not a perfect square.

For all the numbers ending in 1, 4, 5, 6, & 9 and for numbers ending in even zeros, then remove the zeros at the end of the number and apply following tests:
  • Digital roots are 1, 4, 7 or 9. No number can be a perfect square unless its digital root is 1, 4, 7, or 9. You might already be familiar with computing digital roots. (To find digital root of a number, add all its digits. If this sum is more than 9, add the digits of this sum. The single digit obtained at the end is the digital root of the number.)
  • If unit digit ends in 5, ten’s digit is always 2.
  • If it ends in 6, ten’s digit is always odd (1, 3, 5, 7, and 9) otherwise it is always even. That is if it ends in 1, 4, and 9 the ten’s digit is always even (2, 4, 6, 8, 0).
  • If a number is divisible by 4, its square leaves a remainder 0 when divided by 8.
  • Square of even number not divisible by 4 leaves remainder 4 while square of an odd number always leaves remainder 1 when divided by 8.
  • Total numbers of prime factors of a perfect square are always odd.
4539 ends in 9, digit sum is 3. Therefore, 4539 is not a perfect square
5776 ends in 6, digit sum is 7. Therefore, 5776 may be a perfect square

Step 1: A perfect square never ends in 2, 3, 7 or 8

This is the first observation you will make to check if the number is a perfect square or not. For example, consider the example 15623.


By just noticing the number itself, we can conclude that 15623 cannot be a perfect square. We do not have to go to Step 2.

Step 2: Obtain the digital root of the number

How does the digital root of a number would help in determining if a number is a perfect square or not. It turns out; a perfect square will always have a digital root of 0, 1, 4 or 7.

Take the number 15626 for example. This number ends in digits 6. So it satisfies Step 1. But still we cannot conclude, this number as a perfect square.

Let’s take the digital root of this number.

1 5 6 2 6 = 5 + 6 = 11 = 1 + 1 = 2

So, the digital root of this number is 2. A perfect square will never have a digital root 2. Hence, we can conclude 15626 is not a perfect square.

Now, there is a rider for this shortcut though, even if both Steps are satisfied, that does not guarantee that the number is a perfect square.

Let us take up an example here. Consider the number 623461, which is not a perfect square.

Notice that the unit digit is 1. This number could be a perfect square. Let us take the digital root.

6 2 3 4 6 1

The digital root of 623461 is 4. So it satisfies both Step 1 and 2. Still we cannot conclude that 623461 is a perfect square though.

However, this shortcut comes in really handy to eliminate obvious choices which are not a perfect square to solve competitive examination where you need to find the perfect squares.

Is 14798678562 a perfect square? Is 15763530163289 a perfect square?

Examine both the units digits and the digital roots of perfect squares to help determine whether or not a given number is a perfect square.

How-to-check-if-a-number-is-a-perfect-squareAs we know a perfect square can only end in a 0, 1, 4, 5, 6, or 9; this should allow us to determine whether the first of our numbers is a perfect square. However, it isn't sufficient to draw a conclusion about the second number.

Again as we know that if a perfect square ends in 9; it’s tens digit is always even. Alas, even if we do this, it won't rule out numbers ending in 89, because '...89' is a possible square. 

However, as we know no number can be a perfect square unless its digital root is 1, 4, 7, or 9; so, find the digital root of our second number. It’s 5. As 5 isn't in this list, then the number is definitely not a perfect square.

So, we can conclude, a number cannot be an exact or perfect square if
-        it ends in 2, 3,7 or 8
-        it terminates in an odd number of zeros
-        its last digit is 6 but its penultimate (tens) digit is even
-        its last digit is not 6 but its penultimate (tens) digit is odd
-        its last digit is 5 but its penultimate (tens) digit is other than 2
-        its last 2 digits are not divisible by 4 if it is even number


Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
int const * p=5; printf("%d",++(*p));
Compiler error: Cannot modify a constant value.
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
Answer: mmmm
aaaa nnnn

Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
    1. Booking
    2. Availability checking
    3. Cancellation
    4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

 My Solution :

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<iostream.h>#include<time.h>#include<iomanip.h>#include<fstream.h>char f[10]="f";char s[10]="s";int addr,ad,flag,f1,d,m,i,amt;float tamt; class login {public:char id[100];char pass[100];char*password;void getid(){ cout<<"Enter your id:";gets(id); password=getpass("Enter the password:");strcpy(pass,password);}void displayid(){ cout<<"Id:";puts(id); cout<<"Password:";puts(pass);}}; class detail {public:in…