社区讨论
代码求助
灌水区参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo8hxba0
- 此快照首次捕获于
- 2023/10/27 18:54 2 年前
- 此快照最后确认于
- 2023/10/27 18:54 2 年前
原题:P3306
代码:
CPP//the code is from pkl
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
map<LL,LL> x;
LL T,p,a,b,x1,t,ans;
LL binpow(LL n,LL k,LL mod){
LL res=1;n%=mod;
while(k){
if(k&1){
res=res*n%mod;
}
n=n*n%mod;
k>>=1;
}
return res;
}
LL BSGS(LL a,LL b,LL mod){
a%=mod;b%=mod;
if(a==0){
return b==0?1:-1;
}
if(b==1){
return 0;
}
LL m=ceil(sqrt(mod-1)),inv=binpow(a,mod-m-1,mod);
x.clear();
x[1]=m;
for(LL i=1,e=1;i<m;i++){
e=e*a%mod;
if(!x[e]){
x[e]=i;
}
}
for(LL i=0;i<m;i++){
if(x[b]){
LL res=x[b];
return i*m+(res==m?0:res);
}
b=b*inv%mod;
}
return -1;
}
LL get(){
LL inv=binpow(a*x1-x1+b,p-2,p);
LL res=BSGS(a,(a*t-t+b)%p*inv%p,p);
return res==-1?-1:(res+1);
}
int main(){
scanf("%lld",&T);
while(T--){
scanf("%lld%lld%lld%lld%lld",&p,&a,&b,&x1,&t);
ans=get();
printf("%lld\n",ans);
}
}
不知道为什么,样例过了,交上去0分。
回复
共 0 条回复,欢迎继续交流。
正在加载回复...