题目描述:
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.
输入描述:
Each line will contain an signed 32-bits integer N. Process to end of file.
输出描述:
For each case, output the answer in one line.
输入:
15
1050
输出:
3
11
题意:
连续数字和等于n
题解:
方程求解
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
n *= 2;
int ans = 0;
for(int i = 2; i * i <= n; i ++){
if(n % i == 0 && (i + n / i) % 2 == 1) ans ++;
}
printf("%d\n",ans);
}
return 0;
}