HDU1868
详见代码
View Code
1 //设n可以表示成i个连续整数之和,首项为a, 2 //则n=a+(a+1)+……(a+i-1)=i*a+(1+2+……+(i-1))=i*a+(i*(i-1)/2)-->a=(n-(i*(i-1)/2))/i 3 //枚举i,使得a右边能整除,ans++ 4 #include<stdio.h> 5 int main(){ 6 int n; 7 while( scanf("%d",&n)!=-1 ){ 8 int sum=0,i; 9 for( i=1;i<=n;i++ ){ 10 sum+=i; 11 if( sum>n ) 12 break; 13 } 14 int max=i-1; 15 int ans=0; 16 for( int i=2;i<=max;i++ ){ 17 sum=i*(i-1)/2; 18 sum=(n-sum)%i; 19 if( sum==0 ) 20 ans++; 21 } 22 printf("%d\n",ans); 23 } 24 return 0; 25 }
keep moving...