hdu 2715

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2715

题意:给一个n,问能表示成几种连续数字的和的形式。

mark:很简单,当然是枚举连续数字的个数(从1到sqrt(n))。

代码:

 1 # include <stdio.h>
 2 
 3 
 4 int main ()
 5 {
 6     int n, d, ans ;
 7     while (~scanf ("%d", &n))
 8     {
 9         ans = 0 ;
10         for (d = 1 ; d*(d+1) <= 2*n ; d++)
11         {
12             if ((2*n) % d == 0 &&
13                 (2*n/d+1-d)%2 == 0) ans++ ;
14         }
15         printf ("%d\n", ans) ;
16     }
17     return 0 ;
18 }
原文地址:https://www.cnblogs.com/lzsz1212/p/2543858.html