Cod sursa(job #1144598)
| Utilizator | Data | 17 martie 2014 12:45:52 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <stdio.h>
#define LL long long
using namespace std;
void euclid(LL a, LL b, LL &x, LL &y)
{
if (!b)
{
x=1;
y=0;
}
else
{
LL x0, y0;
euclid(b, a%b, x0, y0);
x=y0;
y=x0-(a/b)*y0;
}
}
void sol()
{
LL a, b, x, y;
scanf("%lld %lld", &a, &b);
euclid(a, b, x, y);
for (; x<0; x+=b);
printf("%lld", x);
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
sol();
return 0;
}
