Cod sursa(job #1514861)
| Utilizator | Data | 31 octombrie 2015 18:57:47 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long a,b,x,y,d,t,i,c,n;
void euclid_ext (long long a, long long b, long long &x, long long &y)
{
if(b==0) { x=1; y=0;}
else{
long long xp=0, yp=0;
euclid_ext(b, a%b, xp, yp);
x=yp;
y=xp-(a/b)*yp;
}
}
int main()
{
fin>>a>>n;
euclid_ext(a, n, x, y);
if(x>=0)
fout<<x;
else { x=x-n*(x/n);
x=x+n;
fout<<x;}
return 0;
}
