Pagini recente » Cod sursa (job #1892973) | Cod sursa (job #1181307) | Cod sursa (job #161233) | Cod sursa (job #1607977) | Cod sursa (job #377299)
Cod sursa(job #377299)
#include <fstream>
using namespace std;
const char InFile[]="inversmodular.in";
const char OutFile[]="inversmodular.out";
long long int a,n,x,y;
void gcd(long long int a,long long int b)
{
if(!b){
x=1;
y=0;
}else{
gcd(b,a%b);
long long int aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
ifstream fin(InFile);
fin>>a>>n;
fin.close();
gcd(a,n);
if(x<=0){
x=n+x%n;
}
ofstream fout(OutFile);
fout<<x;
fout.close();
return 0;
}