牛客(多校4):Basic Gcd Problem

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
 

    const int N=1e6+10;
    const long long mod=1e9+7;
    long long t,c,n;
    int CS[N];
    long long f(long long a, long long b){
        long long BS = a;
        long long CS=1;
        while(b){
            if(b&1)CS=CS*BS%mod;
            BS=BS*BS%mod;
            b >>= 1;}
    CS %= mod;
    return CS;
     
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    for(int i=2;i<N;i++){
        CS[i] = max(CS[i], 1);
        for (int j=i+i;j<N;j+=i){
            CS[j] = max(CS[j], CS[i] + 1);
        }
    }
    cin>> t;
while(t-- ){
    long long ans=0;
    cin>>n>>c;
    ans = f(c, CS[n]) % mod;
    cout << ans << "\n";   
    }
    return 0;
}

知识点:GCD

猜你喜欢

转载自blog.csdn.net/qq_46144237/article/details/107477970