Pagini recente » Cod sursa (job #3270587) | Cod sursa (job #2176861) | Cod sursa (job #2702573) | Cod sursa (job #2176908) | Cod sursa (job #3284715)
#include <fstream>
long long modInv(long long a, long long b, long long & x, long long & y){
if(a == 0){
x = 0;
y = 1;
return b;
}
long long x1, y1, lnko = modInv(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return lnko;
}
int main(){
std::ifstream bem("inversmodular.in");
long long a, mod, x, y;
bem >> a >> mod;
bem.close();
modInv(a, mod, x, y);
while(x < 0) x += mod;
std::ofstream kim("inversmodular.out");
kim << x;
kim.close();
return 0;
}