Pagini recente » Cod sursa (job #1855229) | Rating Ciubancan Roxana (Roxana) | Cod sursa (job #2926595) | Cod sursa (job #2131418) | Cod sursa (job #2394900)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long unsigned llu;
void euclid(llu a,llu b,llu &x,llu &y)
{
if(!b)
{
x=1;
y=0;
}else{
llu aux;
euclid(b,a%b,x,y);
aux=x;
x=y;
y=aux-(a/b)*y;
}
}
int main()
{
llu a,n,x,y;
fin>>a>>n;
euclid(a,n,x,y);
if(x<=0)x=n+x%n;
fout<<x;
return 0;
}