Pagini recente » Cod sursa (job #2012979) | Cod sursa (job #1736420) | Monitorul de evaluare | Istoria paginii blog/rezultate-boi-2004 | Cod sursa (job #767358)
Cod sursa(job #767358)
#include <cstdio>
void euclid(int a,int b,int &d,int &x,int &y){
if(b == 0)
{
d = a;
x = 1;
y = 0;
return ;
}
int x0,y0;
euclid(b,a%b,d,x0,y0);
x = y0;
y = x0 - a/b*y0;
}
int main(){
int a,n,d,x,y;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&n);
euclid(a,n,d,x,y);
if( x < 0 )x += (x/n + 1)*n;
printf("%d\n",x);
return 0;
}