Cod sursa(job #3187069)
Utilizator | Data | 27 decembrie 2023 12:13:11 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
void invMod(ll a, ll b, ll &x, ll &y){
ll aux;
if(!b){
x=1;
y=0;
}else{
invMod(b, a%b, x, y);
aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
ll n, a, x, y;
fin>>a>>n;
x=y=0;
invMod(a, n, x, y);
fout<<x;
return 0;
}