Cod sursa(job #2183374)
| Utilizator | Data | 23 martie 2018 09:21:49 | |
|---|---|---|---|
| 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");
ll a, b, c, d, x, y;
void euclid(ll a, ll b, ll &d, ll &x, ll &y){
if(b == 0){
d = a;
x = 1;
y = 0;
} else {
ll x0, y0;
euclid (b, a % b, d, x0, y0);
x = y0;
y = x0 - y0 * (a / b);
}
}
int main(){
in >> a >> b;
euclid(a, b, d, x, y);
while(x < 0)
x += b;
out << x;
return 0;
}
