Cod sursa(job #2344956)
Utilizator | Data | 15 februarie 2019 19:13:29 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
const int d = 1999999973;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int N, P;
int power(int x, int n){
if(n==1)
return x%d;
else if(n%2==0)
return power(x*x, n/2); // 2*
else if(n%2==1)
return power(x*x*x, (n-1)/2);
}
int main(){
fin >> N >> P;
fout << power(N, P);
return 0;
}