标签:
数学题我都不会2333
再次传送门:Orz hzwer
记住[m / i]的分块性质、、、inext = m / (m / i)
1 /************************************************************** 2 Problem: 2956 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:144 ms 7 Memory:808 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <algorithm> 12 13 using namespace std; 14 typedef long long ll; 15 const ll mod = 19940417; 16 const ll p_6 = 3323403; 17 18 ll n, m, ans; 19 20 ll sum(ll x, ll y) { 21 return (y - x + 1) * (x + y) / 2 % mod; 22 } 23 24 ll sum2(ll x) { 25 return x * (x + 1) % mod * (x * 2 + 1) % mod * p_6 % mod; 26 } 27 28 ll calc(ll x) { 29 ll tmp = 0, i, j; 30 for (i = 1, j; i <= x; i = j + 1) { 31 j = x / (x / i); 32 tmp = (tmp + x * (j - i + 1) % mod - sum(i, j) * (x / i)) % mod; 33 } 34 return (tmp + mod) % mod; 35 } 36 37 int main() { 38 ll i, j, s1, s2, s3; 39 scanf("%lld%lld", &n, &m); 40 ans = calc(n) * calc(m) % mod; 41 if (n > m) swap(n, m); 42 for (i = 1; i <= n; i = j + 1) { 43 j = min(n / (n / i), m / (m / i)); 44 s1 = n * m % mod * (j - i + 1) % mod; 45 s2 = (n / i) * (m / i) % mod * (sum2(j) - sum2(i - 1) + mod) % mod; 46 s3 = (n / i * m + m / i * n) % mod * sum(i, j) % mod; 47 ans = (ans - (s1 + s2 - s3) % mod + mod) % mod; 48 } 49 printf("%lld\n", ans); 50 return 0; 51 }
标签:
原文地址:http://www.cnblogs.com/rausen/p/4263143.html