Cod sursa(job #2615360)
| Utilizator | Data | 14 mai 2020 14:45:01 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A, N;
void gcd(long long &x, long long &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
gcd(x, y, b, a % b);
long long aux = x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
ios::sync_with_stdio(false);
long long inv = 0, ins;
fin>>A>>N;
fin.close();
gcd(inv, ins, A, N);
if (inv <= 0)
inv = N + inv % N;
fout<<inv;
fout.close();
return 0;
}
