Cod sursa(job #1365665)
| Utilizator | Data | 28 februarie 2015 14:08:47 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
inline 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() {
int a, n;
fin >> a >> n;
int x, y;
gcd(a, n, x, y);
x %= n;
while(x < 0)
x += n;
fout << x << '\n';
}
