Cod sursa(job #1516430)
Utilizator | Data | 3 noiembrie 2015 00:25:29 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n,p;
int m = 1999999973;
void citire() {
f >> n >> p;
}
long long lgput(long long baza, long long exp) {
int rez = 1 , power = baza;
while(exp) {
if(exp & 1) {
rez = (1LL*rez*power)%m;
}
power = (1LL*power*power)%m;
exp >>=1;
}
return rez;
}
int main() {
citire();
g << lgput(n,p) << "\n";
}