Cod sursa(job #2292961)
Utilizator | Data | 30 noiembrie 2018 12:41:35 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
ll a,md,inv,ins;
void inv_m(ll &x,ll &y,ll a,ll b){
if(!b) x=1,y=0;
else{
inv_m(x,y,b,a%b);
ll aux=x;
x=y; y=aux-y*(a/b);
}
}
int main()
{
f>>a>>md;
inv_m(inv,ins,a,md);
if(inv<=0) inv=md+(inv%md);
g<<inv<<'\n';
return 0;
}