Cod sursa(job #2175995)
Utilizator | Data | 16 martie 2018 20:21:31 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include <iostream>
#include <cstdio>
using namespace std;
int MOD, A, X;
void euclid(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return;
}
int x1, y1;
euclid(b, a%b, x1, y1);
x = y1;
y = x1-(a/b)*y1;
}
void rez()
{
int x, y;
scanf("%d %d", &A, &MOD);
euclid(MOD, A, x, y);
while(y<=0)
y+=MOD;
printf("%d", y);
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
rez();
return 0;
}