Cod sursa(job #1241302)
Utilizator | Muresan Bogdan muresan_bogdan | Data | 13 octombrie 2014 10:34:50 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
#define MOD 1999999973
int n, p;
long long exp(long long a, int b) {
long long rez = 1;
while(b > 0) {
if(b%2) {
b--;
rez = (rez * a) % MOD;
}else {
a = (a * a) % MOD;
b /= 2;
}
}
return rez;
}
int main() {
fin >> n >> p;
cout << exp(n, p);
return 0;
}