Pagini recente » Istoria paginii utilizator/dianafarcas | Cod sursa (job #1897918) | Statistici Laszlofi Zoltan-Yoda (fruits_not_here) | Monitorul de evaluare | Cod sursa (job #1952579)
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a, n;
long long inv, ins;
void gcd(int a, int b, long long& x, long long& y)
{
if(!b)
x=1, y=0;
else
{
gcd(b, a%b, x, y);
long long aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>a>>n;
gcd(a, n, inv, ins);
if(inv<=0)
inv=n+inv%n;
fout<<inv;
return 0;
}