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 |
超简单方法,8行搞定:若(2*n-i*(i-1))mod(2*i)=0就计数器加一,循环i∈[1,trunc(sqrt(2*n))]。根据等差数列求和公式 2*i*a1+i*(i-1)=2*n 枚举i,判断此时除法得到的a1是否为整数即可。 var n,i,ans:longint; begin readln(n); for i:=1 to trunc(sqrt(2*n)) do if (2*n-i*(i-1))mod(2*i)=0 then inc(ans); writeln(ans); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator