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