zoukankan      html  css  js  c++  java
  • hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390

    题意:求一个式子

    题解:看题解,写代码

    第一行就看不出来,后面的sigma公式也不会化简。mobius也不会

    就自己写了个容斥搞一下(才能维持现在的生活

     //别人的题解https://blog.csdn.net/luyehao1/article/details/81672837

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include<ctime>
    using namespace std;
    const int maxn = 1e6 + 1000;
    typedef long long ll;
    ll F[maxn], phi[maxn], inv[maxn];
    ll  N, M, P;
    void init(int n) {
        for (int i = 1; i <= n; ++i) phi[i] = i;
        for (int i = 2; i <= n; ++i) {
            if (i == phi[i]) {
                for (int j = i; j <= n; j += i) phi[j] = phi[j] / i * (i - 1);
            }
        }
    }
    void init2(void) {
        inv[1] = 1;
        for (int i = 2; i <= N; ++i)
            inv[i] = (P - P / i * inv[P%i] % P) % P;
        for (int i = N; i; --i) {
            F[i] = 1ll * (N / i)*(M / i);
            // if(i == 1) cout<<F[i]<<endl;
            for (int j = i + i; j <= N; j += i)
                F[i] -= F    [j];
        }
    }
    int main() {
        int t; cin >> t;
        init(maxn-1);
        while (t--) {    
            cin >>N>>M>>P;
            if (N < M)swap(N, M);
            init2();
            ll ans = 0;
            for (ll i = 1; i <= N; ++i) {
                ans += (ll)i*inv[phi[i]] % P*(F[i] % P) % P;
                ans %= P;
            }
            cout << ans%P << endl;
        }
    }
    /*
    
    */

    GuGuFishtion(hdu 6390 欧拉函数+莫比乌斯函数)

    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    Eclipse的tomcat插件
    sql优化:
    ecipse theme
    load()和get()的区别
    eclipse手动指定启动的jdk版本
    TOD&FIXME&XXX
    命令式和声明式
    显示器调色温
    jdeveloper优化:
    win7 登录后只能使用“临时配置文件”,原来的配置文件无法启用!
  • 原文地址:https://www.cnblogs.com/SuuT/p/9529956.html
Copyright © 2011-2022 走看看