Cod sursa(job #2182298)
| Utilizator | Data | 22 martie 2018 12:00:30 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int gcdExt(int a, int b, long long &x, long long &y){
int gcd;
if(b == 0){
x = 1;
y = 0;
return a;
}
else{
long long x0,y0;
gcd = gcdExt(b,a%b,x0,y0);
x = y0;
y = x0-(a/b)*y0;
return gcd;
}
}
int main(){
int a,b;
long long int x=0,y;
fin>>a>>b;
int gcd = gcdExt(a,b,x,y);
if(x <= 0) x = b*x%b;
fout<<x;
}
