Cod sursa(job #1747767)
Utilizator | Data | 25 august 2016 16:03:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream in ( "lgput.in" );
ofstream out ( "lgput.out" );
int main()
{
int a, b, p;
in>>a>>b;
p = 1;
while ( b > 0 ) {
if ( b % 2 == 1 )
p = p * a;
b = b / 2;
a = a * a;
}
out<<p;
return 0;
}