Pagini recente » Cod sursa (job #2954777) | Cod sursa (job #2552520) | Cod sursa (job #2595834) | Cod sursa (job #2259951) | Cod sursa (job #2195693)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int t;
ll a, b, c, d, x, y;
void gcd(ll a, ll b, ll &d, ll &x, ll &y){
if(b == 0){
d = a;
x = 1;
y = 0;
} else {
ll xx, yy;
gcd(b, a % b, d, xx, yy);
x = yy;
y = xx - yy * (a / b);
}
}
int main(){
in >> a >> b;
gcd(a, b, d, x, y);
x = ((x % b) + b) % b;
out << x;
return 0;
}