Cod sursa(job #2119700)
Utilizator | Data | 1 februarie 2018 15:59:39 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include<fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
void gcd(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
}
else{
int x0, y0;
gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main(){
int A, N;
fin >>A >> N;
int x, y;
gcd(A, N, x, y);
while(x <= 0)
x += N;
fout << x;
}