Cod sursa(job #3000538)
Utilizator | Data | 12 martie 2023 16:08:24 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n;
void cmmdc(ll &x, ll &y, int a, int b)
{
if (!b)
x=1,y=0;
else
{
cmmdc(x,y,b,a%b);
ll aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
ll x=0,y;
f>>a>>n;
cmmdc(x,y,a,n);
if (x<=0)
x=n+x%n;
g<<x;
return 0;
}