Modular Inverse ZOJ - 3609
2017-09-22 10:25
387 查看
题目传送门
题意:ax≡1 (mod m) 求x
思路:就是一个裸的扩展欧几里得,但是要注意一下m为1的情况
题意: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; }
相关文章推荐
- ZOJ 3609 Modular Inverse【exgcd】
- ZOJ-3609(Modular Inverse )(拓展欧几里得)
- J - Modular Inverse ZOJ - 3609 ----逆元
- ZOJ 3609 Modular Inverse【同余问题】
- ZOJ - 3609 —— Modular Inverse 【乘法逆,扩展欧几里得】
- ZOJ-3609-Modular Inverse【同余定理】【9th浙江省赛】
- ZOJ(Modular Inverse)——最小乘法逆元
- (扩展欧几里得)Modular Inverse--Zoj
- ZOJ 3606 Modular Inverse【乘法逆元】
- zoj Modular Inverse
- Modular Inverse [a关于模m的逆 模线性方程]
- ZOJ 3609 Modular Inverse 扩展欧几里得
- POJ 1060/ ZOJ 1026 : Modular Multiplication of Polynomials - f(x)g(x) mod h(x)
- ZOJ 3609 Modular Inverse(扩展欧几里得求逆元)
- 浙江省省赛第一发(扩展欧几里得)J Modular Inverse
- Modular Multiplicative Inverse(模乘逆元)
- zoj 3609 Modular Inverse(逆元)
- ZOJ - 3609 Modular Inverse
- ZOJ 3609
- ZOJ 3609-Modular Inverse