Cod sursa(job #1918750)
Utilizator | Data | 9 martie 2017 16:44:51 | |
---|---|---|---|
Problema | Invers modular | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int A,N;
void euclidext(long long &x, long long &y, int a, int b)
{
if(b==0){
x=1;
y=0;
}
else{
euclidext(x,y,b,a%b);
long long aux=x;
x = y;
y = aux - y * (a / b);
}
}
int main()
{
long long inv=0,ins;
fin>> A >> N;
euclidext(inv,ins,A,N);
if(inv<=0) inv+=N+inv%N;
fout << inv;
return 0;
}