题目链接:点击查看
题目大意:给出一个函数,有 t 次询问,每次询问给出相应的参数,要求计算函数值
题目分析:打个表不难将函数化简为: ,x 为 n 中的质因子个数,而质因子的个数可以 n * sqrt( n ) 暴力去找,当然也可以利用埃氏筛 + dp nlogn 预处理,对于每次询问配合快速幂就能快速求解了
代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int N=1e6+100;
const int mod=1e9+7;
int cnt[N];
LL q_pow(LL a,LL b)
{
LL ans=1;
while(b)
{
if(b&1)
ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.in.txt","r",stdin);
// freopen("data.out.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);
for(int i=2;i<N;i++)
for(int j=i;j<N;j+=i)
cnt[j]=max(cnt[j],cnt[i]+1);
int w;
cin>>w;
while(w--)
{
int n,c;
scanf("%d%d",&n,&c);
printf("%lld\n",q_pow(c,cnt[n]));
}
return 0;
}