Cod sursa(job #1747769)
Utilizator | Data | 25 august 2016 16:04:51 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream in ( "lgput.in" );
ofstream out ( "lgput.out" );
int main()
{
long long 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;
}