Cod sursa(job #1262439)
Utilizator | Data | 13 noiembrie 2014 10:45:19 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <fstream>
using namespace std;
void gcd(int a, int b, int &x, int &y) {
if(!b) {
x = 1;
y = 0;
return;
}
int x0, y0;
gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
int main() {
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n, x, y;
fin >> a >> n;
gcd(a, n, x, y);
x %= n;
fout << x << '\n';
}