zoukankan      html  css  js  c++  java
  • BZOJ3994 [Sdoi2015]约数个数和

    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] = '';
    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
    ", ans);
    69     }
    70     return 0;
    71 }
    View Code

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

    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    error_reporting(“E_ALL”)和ini_set(“display_errors”, “on”)的区别?
    linux命令awk的详解
    Ubuntu 能PING IP但不能PING主机域名的解决方法
    从github checkout子文件夹
    zuul简单使用
    docker for windows 10 添加阿里云镜像仓库无效问题
    Spring Boot 进行Bean Validate和Method Validate
    JVM调优-GC参数
    Spring Aop: 关于继承和execution target this @annotation
    ReentrantLock原理
  • 原文地址:https://www.cnblogs.com/rausen/p/4439053.html
Copyright © 2011-2022 走看看