zoukankan      html  css  js  c++  java
  • hdu 1868 Consecutive sum

    hdu 1868 Consecutive sum

    Problem DescriptionEvery 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.  InputEach line will contain an signed 32-bits integer N. Process to end of file.  OutputFor each case, output the answer in one line.  Sample Input151050  Sample Output311 注: 此题主要公式 (x+y)*(y-x+1)/2=n #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
     int n,num,i,j,x,y;
     while(cin>>n)
     {
      num=0;
      for(i=(int)sqrt(2*n);i>=2;i--)
      {
       if(2*n%i==0)
       {
        x=(2*n/i-i+1)/2;    
        y=(2*n/i+i-1)/2;
        if((y+x)*(y-x+1)==2*n)
        {
         num++;
        }
       }
      }
      cout<<num<<endl;
     }
        return 0;
    }  
  • 相关阅读:
    《大道至简》第一章 编程的精义
    java课堂练习7
    Java课后练习6
    Java课后练习5
    Java课后练习4
    Java课后练习3
    课堂练习
    求和程序实验报告
    大道至简第二章读后感
    课堂作业例子
  • 原文地址:https://www.cnblogs.com/crazyapple/p/2999509.html
Copyright © 2011-2022 走看看