- Related Questions & Answers
- Check if a number can be expressed as sum two abundant numbers in C++
- Check if a number can be expressed as power in C++
- Check if a number can be expressed as a^b in C++
- C++ Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
- Check if a number can be written as sum of three consecutive integers in C++
- Check if a number can be expressed as 2^x + 2^y in C++
- Check if a number can be represented as a sum of 2 triangular numbers in C++
- Check if a number can be expressed as x^y (x raised to power y) in C++
- Check if a number can be represented as sum of non zero powers of 2 in C++
- Program to check a number can be written as a sum of distinct factorial numbers or not in Python
- C++ program to find ways an integer can be expressed as sum of n-th power of unique natural numbers
- Check if a large number can be divided into two or more segments of equal sum in C++
- Find if n can be written as product of k numbers in C++
- Check if a number is a Mystery Numbers in C++
- Check if a number is a Trojan Numbers in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Here we will see if one number can be represented as sum of two or more consecutive numbers or not. Suppose a number is 12. This can be represented as 3+4+5.

There is a direct and easiest method to solve this problem. If a number is power of 2, then it cannot be expressed as sum of some consecutive numbers. There are two facts that we have to keep in mind.

- Sum of any two consecutive numbers is odd, then one of them will be odd, another one is even.
- Second fact is 2
^{n}= 2^{(n-1)}+ 2^{(n-1)}.

#include <iostream> using namespace std; bool isSumofconsecutiveNumbers(int n) { if((n & (n-1)) && n){ return true; } else { return false; } } int main() { int num = 36; if(isSumofconsecutiveNumbers(num)){ cout << "Can be represented"; } else { cout << "Cannot be represented"; } }

Can be represented

Advertisements