Cod sursa(job #1507958)
| Utilizator | Data | 22 octombrie 2015 08:44:32 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long int power(int x, int n)
{
if(n < 0)
return power(1 / x, -n);
else if (n == 0)
return 1;
else if (n == 1)
return x;
else if (n % 2 == 0)
return power(x * x, n / 2);
else if (n % 2 == 1)
return x * power(x * x, (n - 1) / 2);
}
int main()
{
out << power(2, 20);
return 0;
}
