Modular Inverse ZOJ
来源:互联网 发布:关键词大数据 编辑:程序博客网 时间:2024/06/07 22:48
题目传送门
题意:ax≡1 (mod m) 求x
思路:就是一个裸的扩展欧几里得,但是要注意一下m为1的情况
#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <fstream>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <vector>#define MAXN 20100#define MAXE 5#define INF 1000000000#define MOD 9901#define LL long long#define pi acos(-1.0)using namespace std;void exgcd(LL a, LL b, LL &d, LL &x, LL &y) { if (!b) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }}int main() { std::ios::sync_with_stdio(false); int T; cin >> T; LL a, m; for (int kase = 1; kase <= T; ++kase) { cin >> a >> m; if (m == 1) { cout << 1 << endl; } else { LL d, x, y; exgcd(a, m, d, x, y); if (d != 1) { cout << "Not Exist\n"; } else { cout << (x + m) % m << endl; } } } return 0;}
阅读全文
0 0
- zoj 3609 Modular Inverse
- zoj 3609 ( Modular Inverse)
- ZOJ 3609 Modular Inverse
- ZOJ 3609 Modular Inverse
- ZOJ 3609 Modular Inverse
- ZOJ 3609 Modular Inverse
- ZOJ-3609 Modular Inverse
- ZOJ 3609 Modular Inverse
- ZOJ 3609Modular Inverse
- ZOJ 3609 Modular Inverse
- ZOJ-3609 Modular Inverse
- ZOJ 3609-Modular Inverse
- zoj Modular Inverse
- zoj 3609 Modular Inverse
- Modular Inverse ZOJ
- ZOJ 3609 Modular Inverse(模拟)
- zoj 2609 Modular Inverse (ex_gcd)
- zoj 3609 Modular Inverse(求逆元)
- Android相关知识目录
- ActiveMQ系列—ActiveMQ性能优化(下3)(消息存储方案 RDB)
- 零碎的html和css知识点
- VM中,无法使用X86_64模拟器
- 使用mysqlreplicate命令快速搭建 Mysql 主从复制
- Modular Inverse ZOJ
- Kylin设计Cube
- Ubuntu环境下TensorBoard 可视化 不显示数据问题 No scalar data was found...(作者亲测有效)
- java.lang.IllegalStateException: No tab known for tag null
- Python在Windows环境下处理文件路径问题最佳实践
- Codeforces Round #435 (Div. 2)C,D,E,F题目详解
- Java的代码质量优化的注意细节
- struts2 Action如何返回到视图中
- 微信:微信扫码支付、调用统一下单接口、网站支付 + springmvc