2011-04-25 23:37:12 题目地址:http://acm.fzu.edu.cn/problem.php?pid=1304 #include<iostream> #define N 500001 #define M 3012505 using namespace std; int t,i,j,k,dp[N],mark[M]; int main() { int index=0,max=0; dp[0]=0; for(i=0;i<M;i++) mark[i]=0; for(i=1;i<N;i++) { t=dp[i-1]-i; if(t>0&&!mark[t]) dp[i]=t; else dp[i]=t+i+i; mark[dp[i]]=1; } while (~scanf("%d",&k)&&k>-1) { printf("%d/n",dp[k]); } return 0; }