Cod sursa(job #1098320)
| Utilizator | Data | 4 februarie 2014 18:54:58 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int A,MOD,Solution = 1;
void RidicareLaPutereInTimpLogaritmic(long long A, long long P){
while (P) {
if (P%2 == 1) {
Solution = (Solution * A) % MOD;
}
A =(A * A) % MOD;
P = P/2;
}
}
void Read(){
f>>A>>MOD;
}
void Write(){
g<<Solution;
}
int main()
{
Read();
RidicareLaPutereInTimpLogaritmic(A, MOD-2);
Write();
return 0;
}
