Cod sursa(job #1442263)
Utilizator | Data | 24 mai 2015 20:58:39 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include<fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
#define ll long long
ll A,N,X,Y;
void euclid(int a,int b,ll &x,ll &y){
if(!b){
x = 1;
y = 0;
}
else{
euclid(b,a % b,x,y);
ll aux = x;
x = y;
y = aux - y*(a/b);
}
}
int main()
{
in>>A>>N;
euclid(A,N,X,Y);
out<<X;
return 0;
}