Cod sursa(job #2050352)
Utilizator | Data | 28 octombrie 2017 09:31:00 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
ll a,n,y,inv;
void gcd(ll &x,ll &y,ll a, ll b)
{
if(b==0)
x=1,y=0;
else
{
gcd(x,y,b,a%b);
ll aux=x;
x=y;
y=aux-y*(a/b);
}
}
int main()
{
fin>>a>>n;
ll inv;
gcd(inv,y,a,n);
fout<<inv;
return 0;
}