社区讨论
样例过,全WA求条
P10580[蓝桥杯 2024 国 A] gcd 与 lcm参与者 5已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mipp1yl8
- 此快照首次捕获于
- 2025/12/03 15:37 3 个月前
- 此快照最后确认于
- 2025/12/05 14:00 3 个月前
蒟蒻求条:
代码:
CPP#include <bits/stdc++.h>
#define int unsigned long long
#define endl '\n'
using namespace std;
int q,x,y,n,tmp,p[100005];
const int mod=998244353;
int poww(int x,int y,int mod){
int ans=1;
while(y){
if(y&1){
ans*=x;
ans%=mod;
}
y>>=1;
x*=x;
x%=mod;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>q;
while(q--){
memset(p,0,sizeof p);
tmp=0;
cin>>x>>y>>n;
if(y%x!=0){
cout<<0<<endl;
continue;
}
y/=x;
for(int i=2;i*i<=y;i++){//将y/x分解质因数
if(y%i==0){
tmp++;
while(y%i==0){
p[tmp]++;
y/=i;
}
}
}
if(y!=1){
//还有残留的大素数
p[++tmp]=1;
}
int ans=1;
for(int i=1;i<=tmp;i++){
int sz=p[i],cnt=0;
//cnt零时变量,存储当前方案数之和
cnt+=poww(sz+1,n,mod);
cnt%=mod;
cnt-=poww(sz,n,mod);
cnt%=mod;
cnt-=poww(sz,n,mod);
cnt%=mod;
cnt+=poww(sz-1,n,mod);
cnt=(cnt+mod)%mod;
ans*=cnt;
ans%=mod;
}
ans=(ans+mod)%mod;
cout<<ans<<endl;
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...