Cod sursa(job #2195693)
| Utilizator | Data | 17 aprilie 2018 10:14:10 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#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;
}
