Cod sursa(job #3004776)
Utilizator | Data | 16 martie 2023 16:33:16 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int fastpower(int a,int b){
int rez=1;
while(b){
if(b%2){
rez=rez*a;
}
a=a*a;
b/=2;
}
return rez;
}
int main(){
int a,b;
f>>a>>b;
g<<fastpower(a,b);
return 0;
}