Pagini recente » Cod sursa (job #1968850) | Cod sursa (job #990834) | Cod sursa (job #1976327) | Cod sursa (job #601411) | Cod sursa (job #645444)
Cod sursa(job #645444)
#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;
}