Cod sursa(job #1450345)
Utilizator | Data | 12 iunie 2015 20:33:01 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
int n,p;
f>>n>>p;
if(p == 0){
g<<1;
return 0;
}
int rez=1;
while(p){
if(p % 2 == 0){
n= n *n;
p/=2;
}else{
rez=rez *n;
p--;
}
}
g<< rez;
return 0;
}