Cod sursa(job #837545)
Utilizator | Data | 18 decembrie 2012 09:17:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <fstream>
int a[10000];
using namespace std;
int main()
{
ifstream f (lgput.in);
ofstream g (lgput.out);
int n, p, x, i=1, j;
f >> n >> p;
x=1;
while(p!=0)
{
a[i]=p%2;
i++;
p=p/2;
}
for(j=i-1;j>=1; j--)
if (a[j]==0) x=x*x;
else x=x*x*n;
g << x;
}