Pagini recente » Diferente pentru preoni-2007/runda-3/solutii intre reviziile 15 si 14 | Cod sursa (job #609567) | Istoria paginii utilizator/fuxster | Monitorul de evaluare | Cod sursa (job #781356)
Cod sursa(job #781356)
#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)printf("%d\n",x+(x/n+1)*n); else printf("%d\n",x);
return 0;
}