求 卡 常(
查看原帖
求 卡 常(
245875
Ame__楼主2020/8/19 06:51

分数80,8580,85浮动现在(,有没有dalao帮忙卡个常数(

#include<bits/stdc++.h>
    
#define LL long long
    
#define _ 0

#define R register

#define int long long

using namespace std;
    
/*Grievous Lady*/
    
template <typename T> void read(T & t){
    t = 0;int f = 1;char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f =- 1;ch = getchar();}
    do{t = (t << 1) + (t << 3) + ch - '0';ch = getchar();}while(ch >= '0' && ch <= '9');t *= f;
}
    
const int kato = 1e5 + 10;

const int atri = 1e5;

int a , b , c , t , mod;

int prime[kato] , cnt , phi[kato] , mu[kato] , fac[kato] , Fac[kato] , type0[kato] , type1[kato];

int phi_sum[kato] , fac_0[kato] , fac_1[kato] , fac_0_inv[kato] , fac_1_inv[kato];

bool ispri[kato];

inline LL quick_pow(LL a , LL b){
    LL res = 1;
    for(; b ; b >>= 1 , a = a * a % mod){
        if(b & 1){
            res = res * a % mod;
        }
    }
    return res % mod;
}

// void put(int x){
// 	if(x < 0) putchar('-') , x =- x;
// 	if(x >= 10) put(x / 10);
// 	putchar((x % 10) + 48);
// }

inline void pri(){
    for(int i = 1;i <= atri;i ++){
        fac[i] = 1LL * fac[i - 1] * i % mod;
        Fac[i] = 1LL * Fac[i - 1] * (quick_pow(i , i) % mod) % mod;
    }
    for(int i = 2;i <= atri;i ++){
        if(!ispri[i]){
            prime[++ cnt] = i;
            phi[i] = i - 1;
            mu[i] = -1;
        }
        for(int j = 1;j <= cnt && i * prime[j] <= atri;j ++){
            ispri[i * prime[j]] = 1;
            if(i % prime[j] == 0){
                phi[i * prime[j]] = phi[i] * prime[j];
                break;
            }
            phi[i * prime[j]] = phi[i] * (prime[j] - 1);
            mu[i * prime[j]] = -mu[i];
        }
    }
    for(int i = 1;i <= atri;i ++){
        phi_sum[i] = (phi_sum[i - 1] + phi[i]) % (mod - 1);
        type0[i] = fac_0[i] = fac_1[i] = fac_0_inv[i] = fac_1_inv[i] = type1[i] = 1;
    }
    for(int i = 1;i <= atri;i ++){
        if(mu[i] == 1){
            for(int j = i , cnt = 1;j <= atri;j += i , cnt ++){
                type0[j] = 1LL * type0[j] * cnt % mod;
                type1[j] = 1LL * type1[j] * cnt % mod;
            }
        }
        if(mu[i] == -1){
            for(int j = i , cnt = 1;j <= atri;j += i , cnt ++){
                type0[j] = 1LL * type0[j] * quick_pow(cnt , mod - 2) % mod;
                type1[j] = 1LL * type1[j] * quick_pow(cnt , mod - 2) % mod;
            }
        }
    }
    for(int i = 1;i <= atri;i ++){
        fac_0[i] = 1LL * fac_0[i - 1] * type0[i] % mod;
        fac_0_inv[i] = quick_pow(fac_0[i] , mod - 2);
        // cout << fac_0[i] << ' ' << fac_0_inv[i] << '\n';
        fac_1[i] = 1LL * fac_1[i - 1] * quick_pow(type1[i] , i * i % (mod - 1)) % mod;
        fac_1_inv[i] = quick_pow(fac_1[i] , mod - 2);
    }
}

inline int get_type2_(int x , int y){
    int ans = 1;
    for(int l = 1 , r = 0;l <= min(x , y);l = r + 1){
        r = min(x / (x / l) , y / (y / l));
        ans = 1LL * ans * quick_pow(1LL * fac_0[r] * fac_0_inv[l - 1] % mod , 1LL * (x / l) * (y / l) % (mod - 1)) % mod; 
    }
    return (1LL * ans) % mod;
}

inline int get_sum(int a){
    return ((a * (a + 1))>> 1) % (mod - 1);
}

inline int get_type0_f1(int x , int y , int z){
    return quick_pow(1LL * fac[x] , 1LL * y * z % (mod - 1)) % mod;
}

inline int get_type0_f2(int x , int y , int z){
    // cout << x << ' ' << y << ' ' << z << '\n';
    int ans = 1;
    for(int l = 1 , r = 0;l <= min(x , y);l = r + 1){
        r = min(x / (x / l) , y / (y / l));
        // cout << fac_0[r] << ' ' << fac_0_inv[l - 1] << '\n' ;
        ans = 1LL * ans * quick_pow(1LL * fac_0[r] * fac_0_inv[l - 1] % mod , 1LL * (x / l) * (y / l) % (mod - 1)) % mod; 
    }
    // cout << ans << '\n';
    return quick_pow(ans , z);
}

inline int get_type1_f1(int x , int y , int z){
    return quick_pow(1LL * Fac[x] , 1LL * get_sum(y) * get_sum(z) % (mod - 1)) % mod;
}

inline int get_type1_f2(int x , int y, int z){
    int ans = 1;
    for(int l = 1 , r = 0;l <= min(x , y);l = r + 1){
        r = min(x / (x / l) , y / (y / l));
        ans = 1LL * ans * quick_pow(1LL * fac_1[r] * fac_1_inv[l - 1] % mod , 1LL * get_sum(x / l) * get_sum(y / l) % (mod - 1)) % mod;
    }
    return quick_pow(ans , 1LL * get_sum(z) % (mod - 1)) % mod;
}

inline int get_type2_f1(int x , int y , int z){
    int ans = 1;
    for(int l = 1 , r = 0;l <= min(x , min(y , z));l = r + 1){
        r = min(x / (x / l) , min(y / (y / l) , z / (z / l)));
        ans = 1LL* ans * quick_pow(1LL * fac[x / l] % mod , 1LL * (phi_sum[r] - phi_sum[l - 1] + mod - 1) % (mod - 1) * (y / l) % (mod - 1) * (z / l) % (mod - 1)) % mod;
    }
    return (1LL * ans) % mod;
}

inline int get_type2_f2(int x , int y , int z){
    int ans = 1;
    for(int l = 1 , r = 0;l <= min(x , min(y , z));l = r + 1){
        r = min(x / (x / l) , min(y / (y / l) , z / (z / l)));
        ans = 1LL * ans * quick_pow(1LL * get_type2_(x / l , y / l) , 1LL * (phi_sum[r] - phi_sum[l - 1] + mod - 1) * (z / l) % (mod - 1)) % mod;
    }
    return (1LL * ans) % mod;
}

inline int get_type0(){
    int res1 = 1LL * get_type0_f1(a , b , c) * get_type0_f1(b , a , c) % mod;
    int res2 = 1LL * get_type0_f2(a , b , c) * get_type0_f2(a , c , b) % mod;
    // cout << res1 << ' ' << res2 << '\n';
    return (1LL * res1 * quick_pow(res2 , mod - 2)) % mod;
}

inline int get_type1(){
    int res1 = 1LL * get_type1_f1(a , b , c) * get_type1_f1(b , a , c) % mod;
    int res2 = 1LL * get_type1_f2(a , b , c) * get_type1_f2(a , c , b) % mod;
    return (1LL * res1 * quick_pow(res2 , mod - 2)) % mod;
}

inline int get_type2(){
    int res1 = 1LL * get_type2_f1(a , b , c) * get_type2_f1(b , a , c) % mod;
    int res2 = 1LL * get_type2_f2(a , b , c) * get_type2_f2(a , c , b) % mod;
    return (1LL * res1 * quick_pow(res2 , mod - 2)) % mod;
}

inline int Ame_(){
    read(t) , read(mod);
    mu[1] = phi[1] = fac[0] = fac[1] = Fac[0] = Fac[1] = fac_0[0] = fac_0[1] = fac_1[0] = fac_1[1] = fac_0_inv[0] = fac_1_inv[0] = 1;
    pri();
    // for(int i = 1;i <= 10;i ++){
    //     cerr << i << ' ' << mu[i] << ' ' << phi[i] << '\n';
    // }
    // cout << type0[1] << ' ' << type0[2] << ' ' << type0[3] << '\n';
    // for(int i = 1;i <= 10;i ++){
    //     cerr << fac_0_inv[i] << ' ' << fac_1_inv[i] << '\n';
    // }
    for(; t --> 0 ;){
        read(a) , read(b) , read(c);
        printf("%lld %lld %lld\n" , get_type0() , get_type1() , get_type2());
        // put(get_type0());cout << ' ';put(get_type1());cout << ' ';put(get_type2());cout << '\n';
    }
    return ~~(0^_^0);
}
    
int Ame__ = Ame_();
    
signed main(){;}

/*
3 998244853
1 1 1
2 2 2
3 3 3
*/

/*
1 1 1
16 4096 16
180292630 873575259 180292630
*/
2020/8/19 06:51
加载中...