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

Re:超水!! 0MS就ok 代码共享

Posted by tzkq at 2010-03-14 00:13:23 on Problem 2853
In Reply To:Re:超水!! 0MS就ok 代码共享 Posted by:348854308 at 2010-02-19 21:09:41
假设:
n为序列的个数, 2<=n;
i为序列开始那个数, 1<=i;

那么sumup=(2*i+n-1)*n/2  ;
{ps:等差数列求和公式 s=(首项+末项)*个数/2,这里首项=i,末项=i+n-1,项数=n}

再令已知和为x,列方程: (2*i+n-1)*n/2 = x;

变形-> 2*i*n+n*n-n = 2*x ---> i=(2*x-n*n+n)/2*n
{注意这里,i=(2*x/n-n+1)/2,这个就是那个a1}

因为 i>=1>0, 所以 (2*x-n*n+n)>0

变形->  2*x+1/4>n*n-n+1/4  --->  sqrt(2*x+1/4)>n-1/2

则有 n<sqrt(2^x+1/4)+1/2

最后得到n的范围 2<=n<=(int)(sqrt(2^x+1/4)+1/2-1e-9);
{上面的1e-9是修正系数,有必要的}


因为x<2^31, 所以 n<2^16, 这个值为65536, 所以才有那个70000

我们就可以枚举n的值,如果(2*x-n*n+n)被2*n整除话...

然后就墨有然后了.

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