Cod sursa(job #2443481)
| Utilizator | Data | 28 iulie 2019 12:20:13 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void invers_modular(ll &x, ll &y, int a, int b)
{
if (!b)
x = 1, y = 0;
else
{
invers_modular(x, y, b, a % b);
ll aux = x;
x = y;
y = aux - y * (a / b);
}
}
int a,n;
int main()
{
ll inv=0,ins;
in>>a>>n;
invers_modular(inv,ins,a,n);
if(inv <= 0)
inv=n+inv%n;
out<<inv;
return 0;
}
