Given a natural number N, the task is to find the largest N digit Octal number which is a perfect square.
Input: N = 1
4 is the largest 1 digit Octal number which is also perfect square
Input: N = 2
49 is the largest number which is a 2-Digit Octal Number and also a perfect square.
Therefore 49 in Octal = 61
It can be observed that the series of largest numbers which is also a perfect square in Octal is:
4, 61, 744, 7601, 77771, 776001 …..
As we know the digits in the octal system increases when a number Greater than 8k where k denotes the number of digits in the number. So for any N digit number in the octal number system must be less than the value of 8N+1. So, the general term that can be derived using this observation is –
N-Digit Octal Number = octal(pow(ceil(sqrt(pow(8, N))) -1, 2))
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the Largest N digit perfect square number in Base B
- Largest Even and Odd N-digit numbers in Octal Number System
- Smallest N digit number whose sum of square of digits is a Perfect Square
- Largest number that is not a perfect square
- Largest perfect square number in an Array
- Largest factor of a given number which is a perfect square
- Largest Divisor of a Number not divisible by a perfect square
- Number of times the largest perfect square number can be subtracted from N
- Largest and Smallest N-digit Octal Numbers
- Find smallest perfect square number A such that N + A is also a perfect square number
- Smallest and Largest N-digit perfect squares
- Smallest and Largest N-digit perfect cubes
- Check if a number is perfect square without finding square root
- Largest number less than N with digit sum greater than the digit sum of N
- Check if given number is perfect square
- Perfect Square factors of a Number
- Find minimum number to be divided to make a number a perfect square
- Previous perfect square and cube number smaller than number N
- Find the Next perfect square greater than a given number
- Smallest N digit number which is a perfect fourth power
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.