程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU1868:Consecutive sum

HDU1868:Consecutive sum

編輯:C++入門知識

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 15 1050     Sample Output 3 11         [cpp]   #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++)           {  www.2cto.com             if(n%i == 0)               {                   if(i%2!=0)                       j = j+1;                   if(n/i%2!=0)                       j = j+1;               }           }           cout << j << endl;       }          return 0;   }      

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved