10pts求调,玄关
查看原帖
10pts求调,玄关
609926
Aveiro7楼主2024/7/8 15:19

第一个点能A,但是样例输出无解

#include<bits/stdc++.h>
#include<map>
using namespace std;
#define ll int
map<ll,int> mp;
int b,n,p,x,ans;
int bsgs() {
	mp.clear();
	int m=ceil(sqrt(p));
	ll tmp=1;
	for(int i=1; i<=m; i++) {
		tmp=tmp*b%p;
		mp[tmp*n%p]=i;
	}
	int res=1;
	for(int i=1; i<=m; i++) {
		res=res*tmp*p;
		if(mp[res]) {
			ans=m*i-mp[res];
			return ans;
		}
	}
	return -1;
}
int main() {
	cin>>p>>b>>n;
	n%=p,b%=p;
	if(n==1) {
		ans=0;
	} else if(b==0) {
		if(n!=0) {
			ans=-1;
		} else {
			ans=1;
		}
	} else {
		ans=bsgs();
	}
	if(ans>=0) cout<<ans<<endl;
	else cout<<"no solution"<<endl;
	return 0;
}

2024/7/8 15:19
加载中...