题目链接
As a great ACMer, ZYB is also good at math and number theory.
ZYB constructs a function f c ( x ) f_c(x) fc(x) such that:
Give some positive integer pairs ( n i , c i ) (n_i, c_i) (ni,ci), ZYB wants to know f c i ( n i ) m o d ( 1 0 9 + 7 ) f_{c_i}(n_i)\mod (10^9+7) fci(ni)mod(109+7).
The input contains multiple test cases. The first line of input contains one integer T ( 1 ≤ T ≤ 1 0 6 ) (1 \leq T \leq 10^6) (1≤T≤106).
In the following T {T} T lines, each line contains two integers n i , c i ( 1 ≤ n i , c i ≤ 1 0 6 ) n_i, c_i (1 \leq n_i, c_i \leq 10^6 ) ni,ci(1≤ni,ci≤106) describing one question.
For each test case, output one integer indicating the answer.
2
3 3
10 5
3
25
数论+找规律,打表就很容易发现:
答案就是 c f ( n ) c^{f(n)} cf(n), f ( n ) f(n) f(n) 为 n n n 的质因子个数(可重复),然后套一个快速幂就过了~
下面是打表代码:
ll dfs(ll n,ll c){
if(n==1) return 1;
ll ans=0;
for(ll i=1;i<=n-1;i++){
ans=max(ans,c*dfs(__gcd(i,n),c));
}
return ans;
}
求质因子个数我个人认为应该不能暴力,要素筛加质因子分解,这样求是最快的,AC代码如下:
#include
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll N=1e6+10;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll prime[N],k,t,n,c;
bool isprime[N];
void Prime(){
fill(isprime,isprime+N,1);
k=0;
prime[1]=0;
for(ll i=2;i<N;i++){
if(isprime[i]){
prime[k++]=i;
for(ll j=2;i*j<N;j++)
isprime[i*j]=0;
}
}
}
ll solve(ll n){
ll cnt=0,sum=0;
for(ll i=0;i<k&&prime[i]*prime[i]<=n;i++){
if(n%prime[i]==0){
while(n%prime[i]==0){
sum++;
n/=prime[i];
}
}
}
if(n>1) sum++;
return sum;
}
int main(){
Prime();
scanf("%lld",&t);
while(t--){
scanf("%lld%lld",&n,&c);
printf("%lld\n",power(c,solve(n)));
}
}