Given a number N. The task is to count total numbers under N which are both perfect square and cube of some integers.
Input: N = 100 Output: 2 They are 1 and 64. Input: N = 100000 Output: 6
Approach: For a given positive number N to be a perfect square, it must satisfy P2 = N Similarly, Q3 = N for a perfect cube where P and Q are some positive integers.
N = P2 = Q3
Thus, if N is a 6th power, then this would certainly work. Say N = A6 which can be written as (A3)2 or (A2)3.
So, pick 6th power of every positive integers which are less than equal to N.
Below is the implementation of the above approach:
- Count all triplets whose sum is equal to a perfect cube
- Print n numbers such that their sum is a perfect square
- Count of pairs in an array whose sum is a perfect square
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
- Check if product of array containing prime numbers is a perfect square
- Perfect cube greater than a given number
- Smallest perfect cube in an array
- Largest perfect cube number in an Array
- Largest number in an array that is not a perfect cube
- Smallest perfect Cube divisible by all elements of an array
- Check if a number is perfect square without finding square root
- Perfect Square String
- Check if given number is perfect square
- Largest number that is not a perfect square
- Closest perfect square and its distance
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.