Cod sursa(job #2553206)
| Utilizator | Data | 21 februarie 2020 18:54:40 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
ll a,n,x;
void euclid_extins(ll &x,ll &y,ll a,ll b)
{
if (!b)
{
x=1;y=0;
}
else
{
euclid_extins(x,y,b,a%b);
int aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>a>>n;
ll ins=0;
euclid_extins(x,ins,a,n);
if(x<=0)
x=n+x%n;
fout<<x;
return 0;
}
