HDU1868:Consecutive sum

来源:互联网 发布:java ffmpeg log 编辑:程序博客网 时间:2024/05/01 05:26
Problem Description
Every body knew that 15 = 1+2+3+4+5 = 4+5+6 = 7+8. Now give you a number N, tell me how many ways to represent N as a sum of consecutive positive integers. For example, 15 have 3 ways to be found.
 

Input
Each line will contain an signed 32-bits integer N. Process to end of file.
 

Output
For each case, output the answer in one line.
 

Sample Input
151050
 

Sample Output
311
 


 

 

#include <iostream>using namespace std;int main(){    int n,i,j;    while(cin >> n)    {        j = 0;        if(n%2)            j = j+1;        for(i = 2; i*i<=n; i++)        {            if(n%i == 0)            {                if(i%2!=0)                    j = j+1;                if(n/i%2!=0)                    j = j+1;            }        }        cout << j << endl;    }    return 0;}