Pagini recente » Cod sursa (job #3159184) | Cod sursa (job #2868103) | Cod sursa (job #351899) | Cod sursa (job #1929402) | Cod sursa (job #735298)
Cod sursa(job #735298)
#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);
}