Cod sursa(job #2738907)
Utilizator | scarlat marius marius004 | Data | 6 aprilie 2021 15:10:00 |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
long long euclid(long long a, long long b, long long& x, long long& y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
long long xa, ya;
int d = euclid(b, a % b, xa, ya);
x = ya;
y = xa - (a / b) * ya;
return d;
}
int main() {
long long a, b;
f >> a >> b;
long long x, y;
euclid(a, b, x, y);
x = (x+ b) % b;
g << x;
return 0;
}