Pagini recente » Cod sursa (job #1229278) | Cod sursa (job #2860255) | Cod sursa (job #1985976) | Cod sursa (job #1606719) | Cod sursa (job #3171443)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(long long N, long long M, long long &x, long long &y)
{
if (M == 0)
{
x = 1, y = 0;
return;
}
else
{
gcd(M, N % M, x, y);
long long aux=x;
x = y;
y = aux - (N / M) *y;
}
}
int main()
{
long long a, n, x = 0, y = 0;
fin >> a >> n;
gcd(a, n, x, y);
while (x <= 0)
x += n;
fout << x;
}