Cod sursa(job #2910245)
| Utilizator | Data | 18 iunie 2022 19:04:23 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int x, y, d;
void cmmdc(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
x = 1; y = 0; d = a;
}
else
{
int x0, y0;
cmmdc(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int a, m;
fin >> a >> m;
cmmdc(a, m, d, x, y);
while(x <= 0)
x = x + m;
fout << x;
return 0;
}