poj 2000 Gold Coins

题目链接:http://poj.org/problem?id=2000

题目大意:求N天得到多少个金币,第一天得到1个,第二、三天得到2个,第四、五、六天得到3个、、、、以此类推,得到第N天的金币数。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 using namespace std;
 5 int main ()
 6 {
 7    int x,n,p;
 8    while(cin>>n)
 9    {
10        if (n==0)
11        break;
12        x=p=1;
13        int sum=0;
14        while(x<=n)
15        {
16            for(int i=x;i<x+p&&i<=n;i++)
17            sum+=p;
18            x=x+p;
19            p++;
20        }
21        cout<<n<<" "<<sum<<endl;
22    }
23    return 0;
24 }