zoukankan      html  css  js  c++  java
  • UVA 11440 Help Tomisu 欧拉函数 数论

    非常好的数论题 结合了很多不知道的知识点

     易得代码

    #include<iostream>
    #include<unordered_map>
    #include<algorithm>
    #include<string>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<sstream>
    #include<cstdio>
    #define INF 0x3f3f3f3f
    #define eps 1e-8
    #define equals(a,b) (fabs(a-b)<eps)
    #define MOD 100000007
    const int maxn = 1e7+5 ;
    const double PI = acos(-1.0);
    typedef long long ll;
    using namespace std;
    
    int prime[maxn + 5];
    int is_prime[maxn + 5];
    int cnt;
    ll fac[maxn];
    ll phi[maxn];
    ll n, m;
    
    ll exgcd(ll a, ll b, ll& x, ll& y) {
        if (b == 0) {
            x = 1;
            y = 0;
            return a;
        }
    
        ll g = exgcd(b, a % b, x, y);
        ll t = x;
        x = y;
        y = t - a / b * y;
        return g;
    }
    
    
    ll inv(ll a, ll n) {
        ll x, y;
        exgcd(a, n, x, y);
        return (x + n) % n;
    }
    
    void is_Prime() {
        is_prime[0] = is_prime[1] = 1;
        for (int i = 2; i <= maxn; i++) {
            if (!is_prime[i]) {
                prime[cnt++] = i;
                for (int j = 2 * i; j <= maxn; j += i) {
                    is_prime[j] = 1;
                }
            }
        }
    }
    
    void phi_table() {
        fac[0] = fac[1] = 1;
        phi[0] = phi[1] = 1;
        for (ll i = 2; i < maxn - 3; i++) {
            fac[i] = (fac[i - 1] * i) % MOD;
            if (is_prime[i]) {
                phi[i] = phi[i - 1];
                continue;
            }
            phi[i] = phi[i - 1] * (i - 1) % MOD * inv(i, MOD) % MOD;
        }
    }
    
    int main() {
        ll ans;
        is_Prime();
        phi_table();
        while (scanf("%lld%lld", &n, &m), n && m) {
            printf("%lld\n", ((fac[n] * phi[m] - 1) % MOD + MOD) % MOD);
        }
    
        return 0;
    }
  • 相关阅读:
    高级打字机
    不等数列
    间谍网络
    医院设置
    题目编号生成器
    传纸条
    聪明的打字员
    倒水问题
    八数码难题
    生日蛋糕
  • 原文地址:https://www.cnblogs.com/hznumqf/p/12535656.html
Copyright © 2011-2022 走看看