Cod sursa(job #2691964)
Utilizator | Data | 30 decembrie 2020 20:45:19 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <bits/stdc++.h>
#define MAX 20024
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
void euclid(int a, int b, int & x, int & y){
if(!b){
x = y = 1;
}
else{
int x1, y1;
euclid(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
}
}
int main(){
int a, n, x, y;
in>>a>>n;
euclid(a, n, x, y);
while(x < 0)
x += n;
out<<x;
}