Given the size of array N, the task is to construct an array of size N with positive integer elements such that the cube sum of all elements of this array is a perfect square.
Note: Repititions of integers are allowed.
Input: N = 1
Explanation: Cube of 4 is 64, and 64 is perfect square.
Input: N = 6
Output: 5 10 5 10 5 5
Explanation: Cubic sum of array element is (5)3 + (10)3 + (5)3 + (10)3 + (5)3 + (5)3 = 2500, and 2500 is perfect square.
Approach: The idea is to construct array of size, N which contain first N natural number. If closely observed,
cubic sum of first N natural number: (1)3 + (2)3 + (3)3 + (4)3 + …….(N)3 is always perfect square.
Below is the implementation of the above approach.
1, 2, 3, 4, 5, 6,
Time Complexity: O(N) where N is the size of the Array.
Space Complexity: O(1)
- Construct an Array of size N whose sum of cube of all elements is a perfect square
- Count numbers upto N which are both perfect square and perfect cube
- Previous perfect square and cube number smaller than number N
- Smallest perfect cube in an array
- Count of pairs in an Array whose sum is a Perfect Cube
- Largest number in an array that is not a perfect cube
- Largest perfect cube number in an Array
- Smallest perfect Cube divisible by all elements of an array
- Largest perfect square number in an Array
- Count of pairs in an array whose sum is a perfect square
- Smallest perfect square divisible by all elements of an array
- Count of pairs in an array whose product is a perfect square
- Check if product of array containing prime numbers is a perfect square
- Count of elements to be multiplied with integers to make each pair of Array a perfect square
- Array range queries to find the number of perfect square elements with updates
- Find smallest perfect square number A such that N + A is also a perfect square number
- Construct an array from XOR of all elements of array except element at same index
- Smallest N digit number whose sum of square of digits is a Perfect Square
- Check if a number is perfect square without finding square root
- Perfect Cube
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.