Cod sursa(job #228723)
| Utilizator | Data | 7 decembrie 2008 21:10:00 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <cstdio>
typedef long long i64;
int a,n;
void cmmdc(int a,int b,i64 *x,i64 *y){
i64 x0,y0;
if (b==0) *x=1,*y=0;
else
{
cmmdc(b,a%b,&x0,&y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main(){
i64 x,y;
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
scanf("%d %d",&a,&n);
cmmdc(a,n,&x,&y);
printf("%d",((x%n)+n)%n);
return 0;
}
