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 |
Re:用笨办法太慢了,高手能指点指点吗?In Reply To:Re:用笨办法太慢了,高手能指点指点吗? Posted by:fly_away at 2006-08-17 12:03:52 > 假设连续的数第一个为i,共有j个数,则(2 * i + j - 1) * j = 2 * n > 只需求出这个不定方程的解数即可。显然2 * i + j - 1 > j,于是j < sqrt(2 * n), > 方程有解的条件是(2 * n % j == 0) && (j + 2 * n / j) % 2 != 0 有多少个j满足条件就有多少个解,编程实现就很简单了 我也是这么做的,但是好像比较慢,不知道还有没有进一步优化的办法。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator