Cod sursa(job #1498217)
| Utilizator | Data | 8 octombrie 2015 09:51:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include<stdio.h>
using namespace std;
int A, N, x, y, d;
void euclid(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
void read()
{
scanf("%d %d", &A, &N);
}
void solve()
{
euclid(A, N, x, y);
while(x < 0)
x += N;
printf("%d\n", x);
}
int main()
{
freopen("inversmodular.in","r",stdin);
freopen("inversmodular.out", "w",stdout);
read();
solve();
fclose(stdin);
fclose(stdout);
return 0;
}
