Given an integer **N**, the task is to check whether **N** can be represented as the sum of powers of **2** where all the powers are > 0 i.e. **2 ^{0}** cannot contribute to the sum.

**Examples:**

Input:N = 10

Output:1

2^{3}+ 2^{1}= 10

Input:N = 9

Output:0

**Approach:** There are two cases:

- When
**N**is even then it can always be represented as the sum of powers of**2**when**power > 0**. - When
**N**is odd then it can never be represented as the sum of powers of 2 if**2**is not included in the sum.^{0}

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that return true if n ` `// can be represented as the sum ` `// of powers of 2 without using 2^0 ` `bool` `isSumOfPowersOfTwo(` `int` `n) ` `{ ` ` ` `if` `(n % 2 == 1) ` ` ` `return` `false` `; ` ` ` `else` ` ` `return` `true` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 10; ` ` ` `if` `(isSumOfPowersOfTwo(n)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function that return true if n ` ` ` `// can be represented as the sum ` ` ` `// of powers of 2 without using 2^0 ` ` ` `static` `boolean isSumOfPowersOfTwo(` `int` `n) ` ` ` `{ ` ` ` `if` `(n % 2 == 1) ` ` ` `return` `false` `; ` ` ` `else` ` ` `return` `true` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `n = 10; ` ` ` `if` `(isSumOfPowersOfTwo(n)) ` ` ` `System.out.print(` `"Yes"` `); ` ` ` `else` ` ` `System.out.print(` `"No"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function that return true if n ` `# can be represented as the sum ` `# of powers of 2 without using 2^0 ` `def` `isSumOfPowersOfTwo(n): ` ` ` `if` `n ` `%` `2` `=` `=` `1` `: ` ` ` `return` `False` ` ` `else` `: ` ` ` `return` `True` ` ` `# Driver code ` `n ` `=` `10` `if` `isSumOfPowersOfTwo(n): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed ` `# by Shrikant13 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function that return true if n ` ` ` `// can be represented as the sum ` ` ` `// of powers of 2 without using 2^0 ` ` ` `static` `bool` `isSumOfPowersOfTwo(` `int` `n) ` ` ` `{ ` ` ` `if` `(n % 2 == 1) ` ` ` `return` `false` `; ` ` ` `else` ` ` `return` `true` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 10; ` ` ` `if` `(isSumOfPowersOfTwo(n)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function that return true if n ` `// can be represented as the sum ` `// of powers of 2 without using 2^0 ` `function` `isSumOfPowersOfTwo(` `$n` `) ` `{ ` ` ` `if` `(` `$n` `% 2 == 1) ` ` ` `return` `false; ` ` ` `else` ` ` `return` `true; ` `} ` ` ` `// Driver code ` `$n` `= 10; ` `if` `(isSumOfPowersOfTwo(` `$n` `)) ` ` ` `echo` `(` `"Yes"` `); ` `else` ` ` `echo` `(` `"No"` `); ` ` ` `// This code is contributed ` `// by Code_Mech ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Yes

**Time Complexity:** O(1)

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 if a number can be expressed as sum of two Perfect powers
- Check if rows of a Matrix can be rearranged to make Bitwise XOR of first column non-zero
- Check if given number can be represented as sum of two great numbers
- Check whether a number can be represented by sum of two squares
- Check if a number can be represented as a sum of 2 triangular numbers
- Check whether a number can be represented as sum of K distinct positive integers
- Check if a number can be represented as sum of two consecutive perfect cubes
- Check if N can be represented as sum of integers chosen from set {A, B}
- Check if N can be represented as sum of squares of two consecutive integers
- Check if all nodes of the Binary Tree can be represented as sum of two primes
- Check if a given number can be represented in given a no. of digits in any base
- Check whether a number can be represented as difference of two squares
- Check whether a number can be represented by the product of two squares
- Check whether a number can be represented as difference of two consecutive cubes
- Number of ways in which N can be represented as the sum of two positive integers
- Smallest number greater than n that can be represented as a sum of distinct power of k
- Check if sum of array can be reduced to zero by repetitively reducing array element by their index value
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Check if a number from every row can be selected such that xor of the numbers is greater than zero
- Check if X and Y can be made zero by using given operation any number of times

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.