Pagini recente » Cod sursa (job #1341644) | Cod sursa (job #214613) | Cod sursa (job #2398850) | Cod sursa (job #1680591) | Cod sursa (job #2397643)
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;
void gcd(LL &x,LL &y,int a,int b){
if(b==0){
x=1;
y=0;
return;
}
gcd(x,y,b,a%b);
LL aux = x;
x = y;
y = aux - y*(a/b);
}
int main()
{
int a,n;
LL inv = 0,ins;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f>>a>>n;
gcd(inv,ins,a,n);
if(inv<=0)
inv = n + inv%n;
g<<inv;
return 0;
}