Cod sursa(job #1873339)
Utilizator | Data | 8 februarie 2017 22:54:10 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <bits/stdc++.h>
using namespace std;
int n,k;
int putere(int x, int y)
{ if(y==1) return x;
else
if(y%2==0) return putere(x*x,y/2);
else
return x*putere(x*x,y/2);
}
int main()
{freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d",&n,&k);
int ct=putere(n,k);
printf("%d",ct);
return 0;
}