UVA10225 Discrete Logging

题意

BSGS 。

思路

BSGS 。

代码

ll a,b,mod;
ll block;
unordered_map<ll,ll>m;
ll bsgs(ll x,ll y){
//	if(y==1)return 0;
	ll bas=1;
	for(ll i=0;i<block;i++){
		m[bas*y%mod]=i;
		bas=bas*x%mod;
	}
	x=bas;
	bas=1;
	if(!x)return y==0?1:-1;
	for(ll i=1;i<=block;i++){
		bas=bas*x%mod;
		if(m.count(bas)){
			ll res=i*block-m[bas];
			if(res>=0)return res;
		}
	}
	return -1;
}
void solve(){
	//reading had finished in the main fuc. 
	m.clear();
	block=sqrt(mod);
	if(b==1){
		cout<<0<<endl;
		return ;
	}
	ll res=bsgs(a,b);
	if(res==-1)cout<<"no solution"<<endl;
	else cout<<res<<endl;
	return ;
}
posted @   Rnfmabj  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示