Given an integer n, the task is to print n numbers such that their sum is a perfect square.
Input: n = 3
Output: 1 3 5
1 + 3 + 5 = 9 = 32
Input: n = 4
Output: 1 3 5 7
1 + 3 + 5 + 7 = 16 = 42
Approach: The sum of first n odd numbers is always a perfect square. So, we will print the first n odd numbers as the output.
Below is the implementation of the above approach:
1 3 5
- Count numbers upto N which are both perfect square and perfect cube
- 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
- Check if a number is perfect square without finding square root
- Program to print non square numbers
- Perfect Square String
- Largest number that is not a perfect square
- Check if given number is perfect square
- Closest perfect square and its distance
- Check perfect square using addition/subtraction
- Largest perfect square number in an Array
- Count of pairs in an array whose sum is a perfect square
- Largest factor of a given number which is a perfect square
- Find the Next perfect square greater than a given number
- Check whether the number can be made perfect square after adding 1
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.