Cod sursa(job #3036508)
| Utilizator | Data | 24 martie 2023 14:31:01 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
void euclid(int a, int n, int &x, int &y)
{
if (n == 0)
{
x = 1;
y = 0;
}
else
{
int x0, y0;
euclid(n, a%n, x0, y0);
x = y0;
y = x0 - (a/n)*y0;
}
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a, n;
f >> a >> n;
int x, y;
euclid(a, n, x, y);
while(x<0)
x+=n;
g<<x;
}
