POJ 2417 Discrete Logging (BSGS)
来源:互联网 发布:雅思自测软件 编辑:程序博客网 时间:2024/06/05 21:02
AC代码:
#include <iostream>#include <cstdio>#include <string.h>#include <cmath>#include <map>typedef long long int lli;using namespace std;inline lli qp(lli a,lli x,lli c){ lli ans = 1; for(;x;x>>=1){ if(x&1) ans = ans*a % c; a = a*a % c; } return ans;}lli bsgs(lli a,lli b,lli c){ lli m = ceil(sqrt(c)); map<lli,lli> has; lli temp = 1; lli special = b*temp%c; for(int j = 0;j <= m;j++){ has[b*temp%c] = j; temp = temp*a %c; // 注意这里 如果贪图省事不%c的话 会炸lli } temp = qp(a,m,c); lli ans = temp; for(int i = 1;i <= m;i++){ if(has[ans]){ // has.count(ans) T了 然后这里就很有趣了。 ans = (i*m-has[ans]); printf("%lld\n",(ans%c+c)%c); return 1; } if(ans == special){ ans = (i*m); printf("%lld\n",(ans%c+c)%c); return 1; } ans = ans * temp % c; } return 0;}int main(){ lli c,a,b; while(~scanf("%lld%lld%lld",&c,&a,&b)){ if(c%a == 0 || !bsgs(a,b,c) ){ printf("no solution\n"); continue; } } return 0;}
1 0
- POJ 2417 Discrete Logging (BSGS)
- POJ 2417 Discrete Logging BSGS
- [POJ 2417]Discrete Logging:BSGS
- 【bzoj 3239】【POJ 2417】Discrete Logging(BSGS)
- POJ 2417 Discrete Logging(离散对数 BSGS)
- [poj 2417]Discrete Logging 数论 BSGS
- [poj 2417] Discrete Logging · BSGS
- PoJ 2417 Discrete Logging BSGS裸题
- POJ 2417/BZOJ 3239(Discrete Logging-BSGS)[Template:数论]
- POJ 2417 Discrete Logging bsgs算法模板题
- POJ-2417 Discrete Logging (BSGS算法,离散对数)
- [BZOJ3239][poj2417]Discrete Logging(BSGS算法)
- bzoj 3239: Discrete Logging (BSGS)
- poj2417 bzoj3239 Discrete Logging(bsgs)
- 【bzoj3239】Discrete Logging BSGS
- [BZOJ3239][BSGS]Discrete Logging
- Discrete Logging[POJ 2417]
- POJ 2417 Discrete Logging
- 第一天
- React实战-深入源码了解Redux用法之Connect
- 十进制和二进制的转化;原码、反码和补码
- Android RecyclerView自定义点击事件和长按事件
- table does not exists,select 1 from tablename limit 1
- POJ 2417 Discrete Logging (BSGS)
- Codewars 9月刷题
- mvc架构理解
- Windows API Index
- Chrome控制台实用指南
- 二维数组中的查找
- PHP-WAMP 环境与项目配置
- 浅谈Android中MVC、MVP、MVVM模式(三)
- 学习笔记-20160905