题目链接:codeforces 1228C

题目思路:

f ( x , y ) f(x, y) f(x,y) 是所有 x x x 的质因子在 y y y 中出现次数的乘积,题目要求 1 1 1~ n n n 的乘积,故对于每个质因子,统计其出现次数,再求乘积即可。

参考代码:

#include <iostream>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int prime[N];
int tot;
ll qpow(ll a, ll b, ll MOD = mod) {
   
    ll res = 1;
    a %= MOD;
    while (b > 0) {
   
        if (b & 1) {
   
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
int main() {
   
    ll n, x;
    cin >> x >> n;
    ll tmp = x;
    for (int i = 2; i * i <= tmp; i++) {
    // 分解x的质因子
        if (tmp % i == 0) {
   
            prime[tot++] = i;
            while (tmp % i == 0) tmp /= i;
        }
    }
    if (tmp > 1) prime[tot++] = tmp; 
    ll ans = 1;
    for (int i = 0; i < tot; i++) {
   
        ll y = n, cnt = 0;
        while (y) {
    // 计算 1~n 当前质因子出现的次数
            y /= prime[i];
            cnt += y;
        }
        ans = (ans * qpow(prime[i], cnt)) % mod;
    }
    cout << ans << endl;
    return 0;
}