Cod sursa(job #2031551)
Utilizator | Data | 3 octombrie 2017 13:47:39 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
#define in "inversmodular.in"
#define out "inversmodular.out"
using namespace std;
ifstream fin(in);
ofstream fout(out);
typedef long long ll;
inline void Euclid(int a,int b,int &x,int &y)
{
if(b == 0)
{
x = 1;
y = 0;
}
else
{
int x0,y0;
Euclid(b,a%b,x0,y0);
x = y0;
y = x0 - a/b*y0;
}
}
int inv_modular(int a,int mod)
{
int b = mod;
int x,y;
Euclid(a,b,x,y);
return x;
}
int main()
{
int A,N,X;
fin>>A>>N;
X = inv_modular(A,N);
fout<<X;
return 0;
}