BZOJ 3239 [BSGS]
来源:互联网 发布:社区门诊软件 编辑:程序博客网 时间:2024/06/06 04:44
Description
给定
Solution
#include <bits/stdc++.h>using namespace std;typedef long long ll;int A, B, P, Ans;map<int, int> ap;inline int Pow(int a, int b) { int c = 1; while (b) { if (b & 1) c = (ll)c * a % P; a = (ll)a * a % P; b >>= 1; } return c;}inline int Inv(int a, int P) { return Pow(a, P - 2);}int Log(int a, int b, int p) { int m = ceil(sqrt(p)), ia = Inv(Pow(a, m), P), res; res = Inv(b, p); for (int i = 0; i < m; i++) { if (!ap.count(res)) ap[res] = i; res = (ll)res * a % P; } res = 1; for (int i = 0; i <= m; i++) { if (ap.count(res)) return ap[res] + i * m; res = (ll)res * ia % P; } return -1;}int main(void) { while (~scanf("%d%d%d", &P, &A, &B)) { ap.clear(); Ans = Log(A, B, P); if (Ans == -1) puts("no solution"); else printf("%d\n", Ans); }}
阅读全文
2 0
- BZOJ 3239 [BSGS]
- BZOJ 3239 Discrete Logging BSGS
- bzoj 3239: Discrete Logging BSGS
- BZOJ 3239 Discrete Logging BSGS
- bzoj 3239 poj 2417 BSGS
- BZOJ 3239 浅谈BsGs算法
- 11.1 BSGS BZOJ 3239+2242
- bzoj 3239: Discrete Logging (BSGS)
- BZOJ 1467&&2480;3239 扩展BSGS
- 【bzoj】 - 2242 计算器 【BSGS】
- BZOJ 2242 BSGS
- POJ 2417/BZOJ 3239(Discrete Logging-BSGS)[Template:数论]
- 【bzoj 3239】【POJ 2417】Discrete Logging(BSGS)
- BZOJ-2242-计算器-SDOI2011-BSGS
- bzoj 2242: [SDOI2011]计算器 BSGS
- Bzoj 2242: [SDOI2011]计算器(BSGS)
- BZOJ-2995&&2480&&3239 同余方程&Mod&Discrete Logging 拓展BSGS算法
- 【BZOJ】【P3239】【Discrete Logging】【题解】【BSGS】
- 编码习惯
- java UDP多线程回射服务器
- HDU 3068 最长回文(manacher算法)
- django框架对数据库的操作
- HDU 1005 Number Sequence 矩阵快速幂
- BZOJ 3239 [BSGS]
- C#中的回调函数:以最简单的方式讲解最实用的知识点
- 邝斌的ACM模板(相关公式)
- Activemq实现Mysql与SolrCloud同步策略
- 学习Halcon错误总结
- ubuntu定时执行任务crontab的使用
- Struts2-访问Web资源
- HttpurlconnnectionPost请求的数据类型
- Docker-开源的应用容器引擎