Pagini recente » Cod sursa (job #663073) | Cod sursa (job #1081692) | Cod sursa (job #3148989) | Cod sursa (job #1033522) | Cod sursa (job #1033011)
#include <stdio.h>
#define ll long long
int A, N;
void gcd(ll &x, ll &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
gcd(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
ll inv = 0, ins;
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d %d", &A, &N);
gcd(inv, ins, A, N);
if (inv <= 0)
inv = N + inv % N;
printf("%lld\n", inv);
return 0;
}
/*
# include <fstream>
# define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,N;
void euclid( ll &x , ll &y , int a , int b )
{
if( b == 0 )
x = 1 , y = 0;
else
{
euclid(x,y,b,a%b);
ll aux;
x = y;
y = aux - (a/b)*y;
}
}
int main()
{
ll X,Y;
fin >> A >> N;
euclid(X,Y,A,N);
if( X <= 0 ) X = N + X%N;
fout << X;
fin.close();
fout.close();
return 0;
}
*/