Cod sursa(job #3030303)
| Utilizator | Data | 17 martie 2023 16:41:52 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <fstream>
#define int long long
using namespace std;
ifstream cin ("inversmodular.in");
ofstream cout ("inversmodular.out");
void euclid(int a,int b,int &x,int &y)
{
if (b==0)
{
x = 1;
y = 0;
return;
}
int x0,y0;
euclid(b,a%b,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int nr,n;
cin >> nr >> n;
int x,y;
euclid(nr,n,x,y);
while (x<0)
x = x + n;
cout << x;
return 0;
}
