Pagini recente » Cod sursa (job #2442195) | Cod sursa (job #2555029) | Cod sursa (job #1558855) | Cod sursa (job #568812) | Cod sursa (job #2050407)
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
ll A,N;
void citire()
{
fin>>A>>N;
}
void gcd(ll &x, ll &y, ll a, ll b)
{
if(b==0){x=1;y=0;}
else {
gcd(x,y,b,a%b);
ll aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
citire();
ll x,y;
gcd(x,y,A,N);
if(x<0) x+=N;
fout<<x;
return 0;
}