Cod sursa(job #1109038)
| Utilizator | Data | 16 februarie 2014 17:57:36 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.37 kb |
#include <iostream>
#include <fstream>
#include <ext/numeric>
#include <cmath>
using namespace std;
using namespace __gnu_cxx;
int n,p;
long long pow(int x,int k)
{ if (k==0) return 1;
if (k&1) return x*pow(x*x,(k-1)/2);
else return pow(x*x,k/2);
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
g<<pow(n,p);
return 0;
}
