Cod sursa(job #544824)
Utilizator | Data | 2 martie 2011 10:53:00 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<fstream.h>
ifstream F("inversmodular.in");
ofstream G("inversmodular.out");
long long x,y;
int A,B;
void f(long long &x, long long &y, int A,int B)
{if(B==0) x=1,y=0;
else { f(x,y,B,A%B);
long long z=x;
x=y;
y=z-y*(A/B);
}
}
int main ()
{F>>A>>B;
f(x,y,A,B);
if(x<=0) x=B-x%B;
G<<x;
F.close();
G.close();
return 0;
}