Pagini recente » Cod sursa (job #1129871) | Cod sursa (job #722846) | Cod sursa (job #1683931) | Statistici Niste treapati (CNITV_Diaconu_Popovici_Stoica) | Cod sursa (job #2018757)
#include <fstream>
using namespace std;
int x, modulo;
int Invers_Modular(int m)
{
int putere = m - 2;
int sol = 1;
while(putere > 0)
{
if(putere & 1) sol = (sol * x) % m;
x = (x * x) % m;
putere >>= 1;
}
return sol;
}
int main()
{
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
f >> x >> modulo;
g << Invers_Modular(modulo);
return 0;
}