• bzoj 1485 卡特兰数 + 分解因子


    思路:打表可以看出是卡特兰数,但是模数不一定是素数,所以需要分解一下因数。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    
    using namespace std;
    
    const int N = 2e6 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    int n, MOD, tot, p[N], mn[N], cnt[N];
    
    LL fastPow(LL a, LL b) {
        LL ans = 1;
        while(b) {
            if(b & 1) ans = ans * a % MOD;
            a = a * a % MOD; b >>= 1;
        }
        return ans;
    }
    void init() {
        for(int i = 2; i <= 2 * n; i++) {
            if(mn[i]) continue;
             p[++tot] = i; mn[i] = tot;
            for(int j = 2 * i; j <= 2 * n; j += i) {
                if(!mn[j]) {
                    mn[j] = tot;
                }
            }
        }
    }
    
    void getCnt(int x, int op) {
        while(x != 1) {
            cnt[p[mn[x]]] += op;
            x /= p[mn[x]];
        }
    }
    
    int main() {
    
        scanf("%d%d", &n, &MOD);
        init();
    
        for(int i = 2; i <= 2 * n; i++) getCnt(i, 1);
        for(int i = 2; i <= n; i++) getCnt(i, -1);
        for(int i = 2; i <= n + 1; i++) getCnt(i, -1);
    
        LL ans = 1;
        for(int i = 2; i <= 2 * n; i++) ans = ans * fastPow(i, cnt[i]) % MOD;
        printf("%lld
    ", ans);
        return 0;
    }
    
    
    /*
    */
  • 相关阅读:
    Nmap帮助文档解释
    用servlet设置过滤器处理中文乱码
    Linux服务器远程连接window服务器并执行cmd命令
    java中的异常处理
    java的反射机制
    react入门
    多线程编程
    软件工程基本概念
    反射、类加载与垃圾回收
    数据库
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9380574.html
Copyright © 2020-2023  润新知