Cod sursa(job #2543090)
Utilizator | Data | 10 februarie 2020 20:42:42 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void invmod(long long &x,long long &y,int a,int b)
{
if(b==0)
x=1,y=0;
else
{
invmod(x,y,b,a%b);
long long c=x;
x=y;
y=c-y*(a/b);
}
}
int main()
{
long long a,b,x=0,y=0;
fin>>a>>b;
invmod(x,y,a,b);
if(x<=0)
{
x=b+x%b;
}
fout<<x;
}