Cod sursa(job #2873669)
Utilizator | Data | 19 martie 2022 11:17:50 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#define MOD 1999999973
void euclid(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
d = a;
return;
}
int x1, y1;
euclid(b, a%b, d, x1, y1);
x = y1;
y = x1 - (a/b)*y1;
}
int main()
{
int d,x,y;
long long a,b;
fin>>a>>b;
euclid(a,b,d,x,y);
while(x<0)
x=x+b;
fout<<x;
return 0;
}