Cod sursa(job #2035005)
Utilizator | Data | 8 octombrie 2017 20:07:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
int a,b,c=0,rez=1,d=2,cb;
f>>a>>b;
cb=b;
while(b>1){
b=b/2;
c++;
}
rez=a*a;
//cout<<c<<" c"<<endl;
for(int i=0;i<c-1;i++){
rez*=rez;
d*=2;
}
//cout<<d<<" d"<<endl;
//cout<<cb-d<<" cb-d"<<endl;
for(int i=0;i<(cb-d);i++){
rez*=a;
}
g<<rez;
}