Cod sursa(job #2152769)
| Utilizator | Data | 5 martie 2018 19:45:19 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
inline void Euclid(int a, int b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
}
else {
long long xx, yy;
Euclid(b, a % b, xx, yy);
x = yy;
y = xx - (a / b) * yy;
}
}
inline void Read() {
long long inv, inb;
int A, N;
fin >> A >> N;
Euclid(A, N, inv, inb);
if (inv < N)
inv += N;
fout << inv;
}
int main () {
Read();
fin.close(); fout.close(); return 0;
}
