Skip to main content

### How to know or check if a number is a perfect cube?

We often need to know or check if a number is a perfect cube in order to extract the cube root of the number within a very short time, especially in the competitive examinations.

The most straight forward method is to check through factorization. If the prime factors of a number are grouped in triples of equal factors, then that number is called a perfect cube.

In order to check whether a number is a perfect cube or not, we find its prime factors and group together triplets of the prime factors. If no factor is left out then the number is a perfect cube. However if one of the prime factors is a single factor or a double factor then the number is not a perfect cube.

Examine if (i) 106480 and (ii) 19683 are perfect cubes.

106480

One prime factor 2 and the prime factor 5 are not parts of a triplet so 106480 is not a perfect cube.

Is 19683 a perfect cube?

19683

Since the prime factor 3 forms three triplets so 19683 is a perfect cube.

However, factorization method is time consuming and there is an interesting shortcut, using which we can easily and quickly check if the given number is a perfect cube or not.

Before explaining the shortcut, it is very important that the performer knows the concept of digital root or digital sum

Let us summarize the cubes of the numbers till 10 and obtain their digital roots.

 Number Cube Digital Root of the cube 1 1 1 2 8 8 3 27 9 (or 0) 4 64 1 5 125 8 6 216 9 (or 0) 7 343 1 8 512 8 9 729 9 (or 0)

Notice, the digital root of a perfect cube is 1, 8 or 9 (0). However, the converse is not always true. That is, if a number has a digital root of 1, 8 or 9 (or 0), that does not mean, that the given number must be a perfect cube.

So, all perfect cubes must have digital root 18 or (0). Moreover, the digital root of any number's cube can be determined by the remainder the number gives when divided by 3:

• If the number is divisible by 3, its cube has digital root 9;
• If it has a remainder of 1 when divided by 3, its cube has digital root 1;
• If it has a remainder of 2 when divided by 3, its cube has digital root 8.
With this understanding, if we have to check whether a given number is a perfect cube, just obtain the digital root of the given number. If the digital root is not 1, 8 or 9 (0) we can be very sure that the number is not a perfect cube.

Consider an example. Suppose we need to check which from the following is a perfect cube:
• 91348765
• 91733851
• 91449952
• 91944321
Let us obtain the digital root of each of the given number.

The digital root of 91348765 after casting out 9′s is 7, because 9 + 1 + 3 + 4 + 8 + 7 + 6 + 5 = 43 and 4 + 3 = 7.

9 1 3 4 8 7 6 5

So, we can easily conclude 91348765 is not a perfect cube.

Now the digital root of 91733851 is 10 i.e., 1.

9 1 7 3 3 8 5 1

So, 91259809 could be a perfect cube but we cannot conclude from this.

Consider the digital root of other 2 numbers now. The digital root of 91449952 is 7.

9 1 4 4 9 9 5 2

Again we can conclude that this cannot be a perfect cube.

The digital root of 91944321 is 6.

9 1 9 4 4 3 2 1

So again, 91944321 is not a perfect cube.

So, we are left with only one option 91733851 whose digital root is 1. So, we can conclude that 91733851 is a perfect cube.

Finally to reiterate, if the digital root of a number is not 0, 1 or 8, we can easily conclude that the number is not a perfect cube. However, if a number has a digital root of 1, 8 or 0, that does not mean, that the given number must be a perfect cube.

### 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));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
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
Explanation

### 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…

### Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as