其實(shí)這個(gè)題目可以HASH的,呵呵,地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=2081
#include <stdio.h>

int tab[500005];


char hash[4000000];/**//*用于hash*/

void cup ()


{

for ( int i=0; i<3600000; i++ )

{
hash[i] = 0;
}

tab[0] = 0;
hash[ tab[0] ] = 1;
for ( i=1; i<=500000; i++ )

{
int temp = tab[i-1] - i;
if ( temp < 0 )

{
tab[i] = tab[i-1] + i;
}
else

{
if ( hash[temp] )

{
tab[i] = tab[i-1] + i;
}
else

{
tab[i] = temp;
}
}
hash[ tab[i] ] = 1;
}
}

int main ()


{

int num;

cup ();
while ( scanf ( "%d", &num ) != EOF && num != -1 )

{
printf ( "%d\n", tab[num] );
}
return 0;
}





































































