Cod sursa(job #2900392)
Utilizator | Data | 10 mai 2022 20:09:23 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid_extins(int &x, int &y, int a, int b){
if(b == 0){
x = 1;
y = 0;
}
else{
int x1 , y1;
euclid_extins(x1, y1, b, a%b);
x = y1;
y = x1 - y1 * (a / b);
}
}
int main(){
int a, b;
f >> a >> b;
int x, y;
euclid_extins(x,y,a,b);
if(x < 0)
x += b;
g << x;
}