We are given a number N. We need to check if the given number N can be represented as sum of two **Great **numbers. If yes then print those two great numbers else print no. Great numbers are those which are represented in the form : ((b)*(b+1)*(2*b+1))/6 where b is a natural number.

Examples:

Input : N = 35 Output : 5 and 30 Input : 105 Output : 14 and 91 Input : 99 Output : No the given number is not a sum of two great numbers

As we know ((b)*(b+1)*(2*b+1))/6 where b is a natural number represents the sum of square of first b natural numbers. For example if b = 3 then 1+4+9 = 14. So to check if the input number n can be represented as sum of two great numbers then we will first compute all the great numbers less than n in an array. Then we will use two pointer approach to find the pair than can sum up to the given number n.

To compute the array of all the great numbers we will iterate over i=0 to i

Time Complexity: O(N)

Auxiliary Space : O(N)

This article is contributed by **Sanket Singh 2**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

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.

## Recommended Posts:

- Check whether a number can be represented by sum of two squares
- Check if N can be obtained by repetitive addition or subtraction of two given numbers
- Check if a large number can be divided into two or more segments of equal sum
- Check if a number can be written as a sum of 'k' prime numbers
- Numbers within a range that can be expressed as power of two numbers
- Modulo power for large numbers represented as strings
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Check if a number can be written as sum of three consecutive integers
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
- Check if the given two numbers are friendly pair or not
- Check if N can be expressed as product of 3 distinct numbers
- Find two numbers whose sum and GCD are given
- Count primes that can be expressed as sum of two consecutive primes and 1
- First N natural can be divided into two sets with given difference and co-prime sums
- Check if a number can be expressed as x^y (x raised to power y)
- Check if a number can be expressed as power | Set 2 (Using Log)
- Check if a number can be expressed as a^b | Set 2
- Represent a number as a sum of maximum possible number of Prime Numbers
- Sum of common divisors of two numbers A and B
- Closest sum partition (into two subsets) of numbers from 1 to n