Cod sursa(job #1268503)
| Utilizator | Data | 20 noiembrie 2014 23:48:13 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long T, i, a, b, c, D, n;
void euclid( long long &x, long long &y, long long a, long long b){
if( b == 0){
x = 1;
y = 0;
}
else{
euclid(x, y , b, a % b);
long long aux = x;
x = y;
y = aux - (a / b) * y;
}
}
int main()
{
fin >> a >> n;
long long x = 0, y;
euclid(x,y, a, n);
if(x <= 0)
x = n + x % n;
fout << x;
return 0;
}
