Pagini recente » Cod sursa (job #1478415) | Cod sursa (job #2955125) | Cod sursa (job #500482) | Cod sursa (job #1588135) | Cod sursa (job #735854)
Cod sursa(job #735854)
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
long gcd(long a,long b,long &x,long &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
long xaux,yaux,d;
d=gcd(b,a%b,xaux,yaux);
x=yaux;
y=xaux-(a/b)*yaux;
return d;
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
long a,b,c;
int i;
scanf("%ld %ld", &a,&b);
c=1;
long d,x,y;
d=gcd(a,b,x,y);
if(c%d==0)
{
long aux=x*(c/d);
while(aux<0) aux+=b;
printf("%ld\n", aux);
}
scanf("%i", &i);
return 0;
}