Cod sursa(job #2900743)
| Utilizator | Data | 12 mai 2022 08:08:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(long long a, long long b, long long &d, long long &x, long long &y)
{
if(b == 0)
{
d = a;
x = 1;
y = 0;
}
else
{
long long x1, y1;
euclid(b, a % b, d, x1, y1);
x = y1;
y = x1 - 1LL * (a / b) * y1;
}
}
int main()
{
long long a, n;
f >> a >> n;
long long d, x, y;
euclid(a, n, d, x, y);
while(x < 0)
x += n;
g << x;
return 0;
}
