Cod sursa(job #645444)
| Utilizator | Data | 9 decembrie 2011 17:22:22 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
const char InFile[]="inversmodular.in";
const char OutFile[]="inversmodular.out";
ifstream fin(InFile);
ofstream fout(OutFile);
int A,N,x,y,d,t;
void gcd(int A, int B, int &x, int &y)
{
if(B==0)
{
x=1;
y=0;
return;
}
gcd(B,A%B,x,y);
t=x;
x=y;
y=t-y*(A/B);
}
int main()
{
fin>>A>>N;
fin.close();
gcd(A,N,x,y);
fout<<x;
fout.close();
return 0;
}
