# Check if given number can be represented as sum of two great numbers

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.

## Recommended Posts:

- Check if a number can be represented as a sum of 2 triangular numbers
- Check whether a number can be represented by sum of two squares
- Check if a number can be represented as sum of non zero powers of 2
- Check if a given number can be represented in given a no. of digits in any base
- Sum of two numbers where one number is represented as array of digits
- Check whether a number can be represented as sum of K distinct positive integers
- Check if N can be represented as sum of integers chosen from set {A, B}
- Count numbers which can be represented as sum of same parity primes
- Multiply Large Numbers represented as Strings
- Modulo power for large numbers represented as strings
- Check if two numbers have same number of digits
- Check if a number can be written as a sum of 'k' prime numbers
- Check if a number can be expressed as sum two abundant numbers
- Check if a number can be expressed as a sum of consecutive numbers
- Check if a number from every row can be selected such that xor of the numbers is greater than zero