Cod sursa(job #1368217)
Utilizator | Data | 2 martie 2015 15:13:41 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long expo(long a, long b)
{
long x = 1;
while(b)
{
if(b & 1 == 1)
x *= a;
b >>= 1;
a *= a;
}
return x;
}
int main()
{
int a, b;
f >> a >> b;
g << expo(a, b);
}