Cod sursa(job #1463379)
Utilizator | Data | 20 iulie 2015 20:22:57 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int r,a,n,x,y,c[100],k=0,x0,y0;
fin>>a>>n;
x=a;y=n;
while(y)
{
r=x%y;
c[++k]=x/y;
x=y;
y=r;
}
x0=1;y0=0;
while(k)
{
x=y0;
y=x0-c[k--]*y0;
x0=x;
y0=y;
}
while(x0<0)x0+=n;
fout<<x0%n;
return 0;
}