Cod sursa(job #1571098)
Utilizator | Data | 17 ianuarie 2016 09:59:04 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
ifstream fin ("inversmodular.in");
ofstream fout ("inversmodular.out");
int A, N;
void im(long long &x, long long &y, int a, int b)
{
if(!b)
x=1,y=0;
else
{
im(x,y,b,a%b);
long long aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
long long g=0, h;
fin>>A>>N;
im(g,h,A,N);
while(g<=0)
g=N+g;
fout<<g;
return 0;
}