Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

超简单方法,8行搞定:若(2*n-i*(i-1))mod(2*i)=0就计数器加一,循环i∈[1,trunc(sqrt(2*n))]。

Posted by lydliyudong at 2011-08-16 17:09:58 on Problem 2140 and last updated at 2011-08-16 17:10:35
根据等差数列求和公式
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator