Cod sursa(job #1136021)
| Utilizator | Data | 8 martie 2014 18:09:15 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <cstdio>
using namespace std;
void euclid(long long a,long long b,long long &x,long long &y)
{
if(!b)
{
x = 1;
y = 0;
return;
}
long long x1,y1;
euclid(b,a%b,x1,y1);
x = y1;
y = x1 - (a/b)*y1;
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out","w",stdout);
long long N,MOD,a,b,x,y;
scanf("%lld%lld",&N,&MOD);
euclid(N,MOD,x,y);
printf("%d\n",(x+MOD)%MOD);
return 0;
}
