uva10025 The ? 1 ? 2 ? ... ? n = k problem
什么玩意儿
View Code
1 #include<stdio.h> 2 int main() 3 { 4 int T; 5 while(scanf("%d",&T)!= EOF) 6 { 7 while(T--) 8 { 9 int m,k=0,s=0,p; 10 scanf("%d",&m); 11 if(m==0) printf("3\n"); 12 else 13 { 14 if(m<0) m=-m; 15 while(s<m){ 16 k++; 17 s+=k; 18 } 19 p=s-m; 20 if(p%2==0) printf("%d\n",k); 21 else 22 { 23 for(int j=k+1;;j++) 24 { 25 p=p+j; 26 if(p%2==0){ 27 printf("%d\n",j); 28 break; 29 } 30 } 31 } 32 } 33 if(T) printf("\n"); 34 } 35 } 36 return 0; 37 }