Cod sursa(job #2848150)
Utilizator | Data | 12 februarie 2022 10:35:56 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
#define ll long long int
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(ll a,ll b,ll &d,ll &x,ll &y)
{
if(!b)
{
d=a;
x=1;
y=0;
}
else
{
ll x0,y0;
euclid(b,a%b,d,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
ll a,n;
int main()
{
f>>a>>n;
ll d,x,y;
euclid(a,n,d,x,y);
g<<x%n;
return 0;
}