Cod sursa(job #2589222)
Utilizator | Data | 25 martie 2020 22:09:11 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void EuclidExtins(int a, int b, int d, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
d = a;
}
else{
int x0, y0;
EuclidExtins(b, a%b, d, x0, y0);
x = y0;
y = x0 - y0 * (a/b);
}
}
int main(){
int A,N,d,x,y; f>>A>>N;
EuclidExtins(A,N,d,x,y);
while(x < 0) x += N;
g<<x;
}