Cod sursa(job #1249362)
Utilizator | Data | 26 octombrie 2014 21:47:05 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.63 kb |
#include <fstream>
#define mod 1999999973
#define LL long long
using namespace std;
LL N, P, Result;
LL Exp(LL Base, LL Power) {
LL result = 1;
for(int mask = 1; mask <= Power; mask <<= 1) {
if(Power & mask)
result = (result * Base) % mod;
Base = (Base * Base) % mod;
}
return result;
}
void Read() {
ifstream in("lgput.in");
in >> N >> P;
in.close();
}
void Write() {
ofstream out("lgput.out");
out << Result << '\n';
out.close();
}
int main() {
Read();
Result = Exp(N, P);
Write();
return 0;
}