http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2396

要注意细节

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define ll long long
using namespace std;

const int N=1000005;
ll sum[N];
int main()
{
    //freopen("data.in","r",stdin);
    memset(sum,0,sizeof(sum));
    for(ll x=4;x<N;++x)
    sum[x]=((x-1)*(x-2)/2-(x-1-(x/2)))/2;
    for(int i=1;i<N;++i)
    sum[i]=sum[i]+sum[i-1];
    int n;
    while(cin>>n)
    {
        if(n<3)break;
        cout<<sum[n]<<endl;
    }
    return 0;
}

 

posted on 2013-07-05 21:06  夜->  阅读(155)  评论(0编辑  收藏  举报