Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
水一下/* Name: Copyright: Author: chenjiang Date: 24-08-09 15:50 Description: */ #include<iostream> using namespace std; bool p[5000000]; int a[500001]; int main() { int i,n; p[0]=1;a[0]=0; memset(p,0,sizeof(p)); for(i=1;i<=500000;i++) { if(a[i-1]-i>0&&p[a[i-1]-i]==0) { a[i]=a[i-1]-i;p[a[i]]=1; } else { a[i]=a[i-1]+i;p[a[i]]=1; } } while(cin>>n) { if(n==-1)break; cout<<a[n]<<endl; } system("pause"); return 0; } /* 7 20 10000 18658 500000 626684 -1 */ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator