Cod sursa(job #1247668)
Utilizator | Data | 23 octombrie 2014 11:00:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<iostream>
#include<fstream>
using namespace std;
int main(){
ifstream f("lgput.in", ios::in);
ofstream g("lgput.out", ios::out);
long long N, P, prod = 1;
f >> N >> P;
while (P > 1){
if (P % 2 == 0)
{
N = N*N;
P /= 2;
}
else{
prod *= N;
P--;
}
}
prod *= N;
g << prod << '\n';
f.close();
g.close();
return 0;
}