Cod sursa(job #2685100)
| Utilizator | Data | 15 decembrie 2020 23:03:47 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int Euclid(int a, int b, long long &x, long long &y){
if (b == 0){
x = 1;
y = 0;
return a;
}
else{
long long x0, y0;
int d = Euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
}
int main(){
int a, n;
fin >> a >> n;
long long x, y, d;
d = Euclid(a, n, x, y);
while (x < 0) x = x + n * 100;
x = x % n;
fout << x;
fin.close();
fout.close();
return 0;
}
