Cod sursa(job #3161701)
| Utilizator | Data | 27 octombrie 2023 19:37:26 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(long long a, long long b, long long &x, long long &y)
{
if(b==0)
{
x=1;
y=0;
}
else
{
euclid(b, a%b, x, y);
int aux=x;
x=y;
y=aux-(a/b)*x;
}
}
int main()
{
long long a, n;
fin>>a>>n;
long long x=0, y;
euclid(a, n, x, y);
while(x<0)
{
x+=n;
}
fout<<x;
return 0;
}
