标签:sum stream 多少 推导 div end clu iostream return
题意:给出n<=1e7 求有多少个连续数之和等于k
x+x+1+....x+k=n
(k+1)k/2+(k+1)x=n
(k+1)k+(k+1)2x=2*n
(k+1)*(2x+k)=2*n 2*n为偶 k+1,2x+k都为2*n因子 &&一奇一偶
得到:2*n有多少个奇因子(或者偶因子)就有多少对解 (k,n固定可以得到首项x 得出一解)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=3e5+20;
//
string s;
ll n;
bool check(ll x,ll y)
{
return (x+y)*(y-x+1)>=2*n;
}
int main()
{
while(cin>>n)
{
int cnt=0;
n=n*2;
for(int i=1;i*i<=n;i++)
{
int x=n/i;
if(n%i==0)
{
if(x%2||i%2)//2*n 一个因数为奇 另外一个肯定为偶数
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}
标签:sum stream 多少 推导 div end clu iostream return
原文地址:http://www.cnblogs.com/HIKARI1149/p/6896655.html