当前位置: 代码迷 >> 综合 >> 牛客多校4 - Basic Gcd Problem(预处理质因子的个数)
  详细解决方案

牛客多校4 - Basic Gcd Problem(预处理质因子的个数)

热度:63   发布时间:2024-01-30 14:05:35.0

题目链接:点击查看

题目大意:给出一个函数,有 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;
}

 

  相关解决方案