Pagini recente » Cod sursa (job #3224121) | Cod sursa (job #3153467) | Cod sursa (job #1766232) | Cod sursa (job #2823461) | Cod sursa (job #735296)
Cod sursa(job #735296)
#include <cstdio>
void euclid(int a,int b,int &d,int &x,int &y){
if(b==0){
x=1;
y=0;
d=a;} else {
int x0,y0;
euclid(b,a%b,d,x0,y0);
x=y0;
y=x0-a/b*y0; }
}
int main(){
int a,b,d,x,y;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&b);
euclid(a,b,d,x,y);
if(x>0)printf("%d\n",x); else printf("%d\n",x+(x/b+(x%b))*b);
}