orz jcpwfloi= =

窝本来写了的说。。。被JCPW大爷D惹。。。那就看他的好了!2333

 

 1 /**************************************************************
 2     Problem: 3994
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:2664 ms
 7     Memory:2320 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12  
13 using namespace std;
14 typedef long long ll;
15 const int N = 5e4 + 5;
16 const int Maxlen = N * 2 * 7;
17  
18 int n, m;
19 int u[N], f[N], d[N], p[N], cnt_p;
20 bool isn_p[N];
21 ll ans;
22  
23 char buf[Maxlen], *c = buf;
24 int Len;
25  
26 inline int read() {
27     static int x;
28     x = 0;
29     while (*c < '0' || '9' < *c) ++c;
30     while ('0' <= *c && *c <= '9')
31         x = x * 10 + *c - '0', ++c;
32     return x;
33 }
34  
35 inline void get() {
36     int i, j, k;
37     for(u[1] = d[1] = 1, i = 2; i < N; ++i) {
38         if (!isn_p[i])
39             p[++cnt_p] = i, u[i] = -1, d[i] = 2, f[i] = 1;
40         for (j = 1; j <= cnt_p; ++j) {
41             k = i * p[j];
42             if (k >= N) break;
43             isn_p[k] = 1;
44             if (i % p[j] == 0) {
45                 u[k] = 0, f[k] = f[i] + 1, d[k] = d[i] / f[k] * (f[k] + 1);
46                 break;
47             }
48             u[k] = -u[i], d[k] = d[i] * 2, f[k] = 1;
49         }
50     }
51 }
52  
53 int main() {
54     Len = fread(c, 1, Maxlen, stdin);
55     buf[Len] = '\0';
56     int T, i, j;
57     T = read();
58     get();
59     for (i = 2; i < N; ++i)
60         d[i] += d[i - 1], u[i] += u[i - 1];
61     while (T--) {
62         n = read(), m = read();
63         if (n > m) swap(n, m);
64         for (ans = j = 0, i = 1; i <= n; i = j + 1) {
65             j = min(n / (n / i), m / (m / i));
66             ans += 1ll * (u[j] - u[i - 1]) * d[n / i] * d[m / i];
67         }
68         printf("%lld\n", ans);
69     }
70     return 0;
71 }
View Code

(不过呢。。。窝比他快)

By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
posted on 2015-04-19 13:53  Xs酱~  阅读(411)  评论(0编辑  收藏  举报