Pagini recente » Cod sursa (job #2554181) | Cod sursa (job #1300651) | Cod sursa (job #2637859) | Cod sursa (job #2980277) | Cod sursa (job #1398358)
#include <iostream>
#include <fstream>
#include <cmath>
#define LL long long
using namespace std;
void cmmdc(LL &x,LL &y,int a,int b)
{
if(b==0)
{
x=1;
y=0;
}
else
{
cmmdc(x,y,b,a%b);
LL aux=x;
x=y;
y=aux - y * ( a / b );
}
}
int main()
{
int a,n;
LL inv=1,y;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>a>>n;
cmmdc(inv,y,a,n);
if(inv<=0)
inv=n + inv%n;
g<<inv;
}