Pagini recente » Cod sursa (job #135284) | Cod sursa (job #2615126) | Cod sursa (job #2342760) | Cod sursa (job #1432300) | Cod sursa (job #541717)
Cod sursa(job #541717)
#include<fstream.h>
#include <stdio.h>
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
void gcd(long long &x, long long &y, int a, int b)
{
long long aux;
if (!b)
x = 1, y = 0;
else
{
gcd(x, y, b, a % b);
aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
long long inv = 0, ins;
fin>>A>>N;
gcd(inv, ins, A, N);
if (inv <= 0)
inv = N + inv % N;
fout<<inv;
return 0;
}
/*date.in: 5 7
date.out: 3 // 5*3=15/7=2, restul 1*/