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 |
这样怎么也tle不能理解了#include <iostream> using namespace std; int k; __int64 mod_sum(int n) { int d = k/n; int t1 = n; int t2 = k/(d + 1); int s, e; __int64 sum = 0; while(t1 - t2 > 10) { s = k%t1; e = k%(t2 + 1); sum += __int64(s + e)*(t1 - t2)/2; d ++; t1 = t2; t2 = k/(d + 1); } int i; for(i = 2; i <= t1; i ++) sum += k%i; return sum; } int main() { int n; scanf("%d %d", &n, &k); __int64 sum = 0; if(n == 1) sum = 0; else if(k == 1) sum = n - 1; else { if(n <= k) sum = mod_sum(n); else { sum = mod_sum(k); sum += __int64(k)*(n - k); } } printf("%I64d\n", sum); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator