• Bzoj 2190 仪仗队(莫比乌斯反演)


    题面

    bzoj

    洛谷

    题解

    看这个题先大力猜一波结论

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using std::min; using std::max;
    using std::swap; using std::sort;
    using std::__gcd;
    typedef long long ll;
    
    template<typename T>
    void read(T &x) {
        int flag = 1; x = 0; char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
        while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
    }
    
    const int N = 4e4 + 10;
    int n, ret;
    bool a[N][N];
    
    int main () {
    #ifdef OFFLINE_JUDGE
        freopen("233.in", "r", stdin);
        freopen("233.out", "w", stdout);
    #endif
        scanf("%d", &n);
        for(int i = 2; i <= n; ++i)
            for(int j = 2; j <= n; ++j) {
                int tmp = __gcd(i, j);
                int tmpi = i / tmp, tmpj = j / tmp;
                if(!a[tmpi][tmpj]) ++ret, a[tmpi][tmpj] = true;
            }
        printf("%d
    ", ret + 2);		
        return 0;
    }
    

    然后:

    1.jpg

    很接近了,仔细一想,应该是:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using std::min; using std::max;
    using std::swap; using std::sort;
    using std::__gcd;
    typedef long long ll;
    
    template<typename T>
    void read(T &x) {
        int flag = 1; x = 0; char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
        while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
    }
    
    const int N = 4e4 + 10;
    int n, ret;
    bool a[N][N];
    
    int main () {
    #ifdef OFFLINE_JUDGE
        freopen("233.in", "r", stdin);
        freopen("233.out", "w", stdout);
    #endif
        scanf("%d", &n);
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) {
                int tmp = __gcd(i, j);
                if(tmp == 1) ++ret/*, a[tmpi][tmpj] = true*/;
            }
        printf("%d
    ", ret);
        return 0;
    }
    

    然后过了:

    2.jpg

    那不就是$Bzoj1101 Zap$了,直接蒯(注意特判一下$n==1$的情况)

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using std::min; using std::max;
    using std::swap; using std::sort;
    typedef long long ll;
    
    template<typename T>
    void read(T &x) {
        int flag = 1; x = 0; char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
        while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
    }
    
    const int N = 4e4 + 10;
    int t, n, mu[N], g[N], prime[N], cnt;
    long long sum[N]; bool notprime[N];
    
    void getmu(int k) {
        mu[1] = 1;
        for(int i = 2; i <= k; ++i) {
            if(!notprime[i]) prime[++cnt] = i, mu[i] = -1;
            for(int j = 1; j <= cnt && prime[j] * i <= k; ++j) {
                notprime[prime[j] * i] = true;
                if(!(i % prime[j])) break;
                mu[prime[j] * i] = -mu[i];
            }
        }
        for(int i = 1; i <= k; ++i)
            sum[i] = sum[i - 1] + 1ll * mu[i];
    }
    
    int main () {
    #ifdef OFFLINE_JUDGE
        freopen("233.in", "r", stdin);
        freopen("233.out", "w", stdout);
    #endif
        getmu(40000); 
        read(n); ll ans = n > 1 ? 2 : 0; --n;
        for(int l = 1, r; l <= n; l = r + 1) {
            r = n / (n / l);
            ans += (sum[r] - sum[l - 1]) * (n / l) * (n / l);
        }
        printf("%lld
    ", ans);
        return 0;
    }
    
  • 相关阅读:
    大二暑假学习第一周
    PyQt5+pycharm 中对生成的.py文件无法运行的问题
    尚筹网19总结
    尚筹网19项目部署
    MAC远程连接Linux
    尚筹网17订单、支付
    尚筹网16确认回报、订单
    支付宝沙箱环境
    内网穿透
    支付宝开发平台使用
  • 原文地址:https://www.cnblogs.com/water-mi/p/10185146.html
Copyright © 2020-2023  润新知