Cod sursa(job #2228581)
| Utilizator | Data | 4 august 2018 12:19:39 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
void euclid_extins(long long a, long long b, long long &x, long long &y, long long &d){
if(b == 0){
x = 1;
y = 0;
d = a;
return ;
}
euclid_extins(b, a%b, x, y, d);
long long newx = y;
long long newy = x - y*(a/b) ;
x = newx;
y = newy;
}
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int main()
{
long long n, a, x, y, d;
fin >> a >> n;
euclid_extins(a, n, x, y, d);
x %= n;
if(x < 0) x += n;
fout << x;
return 0;
}
