【BZOJ】【P3239】【Discrete Logging】【题解】【BSGS】
来源:互联网 发布:java 当前时间戳 编辑:程序博客网 时间:2024/06/01 09:53
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3239
裸题
Code:
#include<bits/stdc++.h>using namespace std;typedef long long LL;LL p,a,b;LL pw(LL x,LL k,LL p){LL ans=1;for(;k;k>>=1){if(k&1)ans=(ans*x)%p;x=(x*x)%p;}return ans;} void solve(){a%=p;b%=p;map<LL,LL>hash;LL m=ceil(sqrt(p)),am=pw(a,m,p),v=pw(a,p-2,p),e=1;hash[b]=0;for(int i=1;i<=m;i++)if(!hash.count(b*v%p))hash[(b*=v)%=p]=i;//cout<<b<<" ";cout<<endl;for(int i=0;i<=m;i++){if(hash.count(e)){cout<<i*m+hash[e]<<endl;return;}e=e*am%p;}puts("no solution");}int main(){while(cin>>p>>a>>b)solve();return 0;}
0 0
- 【BZOJ】【P3239】【Discrete Logging】【题解】【BSGS】
- BZOJ 3239 Discrete Logging BSGS
- bzoj 3239: Discrete Logging BSGS
- BZOJ 3239 Discrete Logging BSGS
- bzoj 3239: Discrete Logging (BSGS)
- 【bzoj3239】Discrete Logging BSGS
- [BZOJ3239][BSGS]Discrete Logging
- 【BSGS】POJ2417[Discrete Logging]&POJ3243[Clever Y]题解
- POJ 2417/BZOJ 3239(Discrete Logging-BSGS)[Template:数论]
- 【bzoj 3239】【POJ 2417】Discrete Logging(BSGS)
- POJ 2417 Discrete Logging BSGS
- [POJ 2417]Discrete Logging:BSGS
- BZOJ-2995&&2480&&3239 同余方程&Mod&Discrete Logging 拓展BSGS算法
- 【BZOJ 3239】 Discrete Logging
- bzoj-3239 Discrete Logging
- [poj 2417]Discrete Logging 数论 BSGS
- [poj 2417] Discrete Logging · BSGS
- [BZOJ3239][poj2417]Discrete Logging(BSGS算法)
- ClassNotFound问题即maven dependencies没有加入Deployment Assembly的解决
- ARM的触摸屏启动
- VS 2008 解决方案的目录结构设置和管理 [整理]
- UVa524 - Prime Ring Problem 枚举排列模板题
- poj 2533 Longest Ordered Subsequence
- 【BZOJ】【P3239】【Discrete Logging】【题解】【BSGS】
- Leetcode_96_Unique Binary Search Trees
- [转]iOS http文件下载断点续传
- Apple Watch Kit(2)- Actionable Notifications
- Bootstrap分页插件--Bootstrap Paginator
- ARM编译
- 过滤器Filter使用
- adb常用命令学习(二)--安装本地应用
- pymongo清除数据