Cod sursa(job #1348570)
| Utilizator | Data | 19 februarie 2015 19:28:46 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
//MS
#include <cstdio>
long long s1 , s2;
int a, m;
void euclid (long long &x, long long &y, int a, int b)
{
if (b==0)
{
x = 1;
y = 0;
}
else
{
long long d;
euclid(x, y, b, a % b);
d= x;
x = y;
y = d - (a / b) * y;
// y = d - y * (a / b);
}
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%d %d", &a, &m);
euclid(s1, s2, a, m);
if (s1 <= 0)
s1 = m + s1 % m;
printf("%d\n", s1);
return 0;
}
