Pagini recente » Borderou de evaluare (job #3152565) | Borderou de evaluare (job #1514162) | Borderou de evaluare (job #1517283) | Cod sursa (job #809848) | 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;
}