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 |
短代码假设解为i,则: 1. i*(i+1)/2 >= S 2. i*(i+1)/2 - S 为偶数,因为 1..i 中任意一个数字变为-号后,i*(i+1)/2 与 Sigma() 差值必为偶数,且这个差值可以取 0、2、4、6 …… 所以: int main() { int s,i; for(scanf("%d",&s),s=-s,i=1;s<0||s%2;s+=i++); printf("%d\n",--i); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator