Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define li long long
- li gcd(li a, li b) {
- return b ? gcd(b, a % b) : a;
- }
- int gcdex(li a, li b, li& x, li& y) {
- if (a == 0) {
- x = 0; y = 1;
- return b;
- }
- li x1, y1;
- li d = gcdex(b % a, a, x1, y1);
- x = y1 - (b / a) * x1;
- y = x1;
- return d;
- }
- int main() {
- long long n, q;
- cin >> n >> q;
- if (gcd(n, q) != 1)
- cout << -1;
- else {
- li x, y;
- gcdex(q, n, x, y);
- x = (x % n + n) % n;
- cout << x;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement