Cod sursa(job #1162998)
| Utilizator | Data | 1 aprilie 2014 09:08:46 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
using namespace std;
long long A, N;
void euclid(long long a, long long b, long long &d, long long &x, long long &y) {
if(b == 0) {
a = d;
x = 1;
y = 0;
}
else {
long long x0 = 0, y0 = 0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f >> A >> N;
long long d = 1, x = 0, y = 0;
euclid(A, N, d, x, y);
while(x < 0)
x += N;
g << x << "\n";
f.close();
g.close();
return 0;
}
