Pagini recente » Cod sursa (job #117906) | Cod sursa (job #1170658) | Cod sursa (job #2592736) | Cod sursa (job #388299) | Cod sursa (job #541710)
Cod sursa(job #541710)
#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