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 = 10Output:1

2^{3}+ 2^{1}= 10Input:N = 9Output: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;` `}` |

## 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"` `);` ` ` `}` `}` |

## 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` |

## 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"` `);` ` ` `}` `}` |

## 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` `?>` |

## Javascript

`<script>` `// Javascript 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` `var` `n = 10;` `if` `(isSumOfPowersOfTwo(n))` ` ` `document.write(` `"Yes"` `);` `else` ` ` `document.write(` `"No"` `);` `// This code is contributed by noob2000.` `</script>` |

**Output:**

Yes

**Time Complexity:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the **Essential Maths for CP Course** at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer **Complete Interview Preparation Course****.**