Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a number n, the task is to check whether it can be expressed as a sum of two or more consecutive numbers or not.

**NOTE: **Return "1" if number can be expressed as sum of consecutives else "0". (Without the double quotes)

**Example 1:**

Input: n = 10Output:1Explanation: It can be expressed as sum of two or more consecutive numbers 1+2+3+4.

**Example 2:**

**Input:** n = 16
**Output: **0
**Explanation**: It cannot be expressed as
sum of two or more consecutive numbers.

**Your Task: **

You dont need to read input or print anything. Complete the function **canBeSumofConsec****() **which takes n as input parameter and returns 1 if number can be expressed as sum of consecutives else 0.

**Expected Time Complexity:** O(1)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1<= n <=10^{18}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Sum of Consecutives

...