Cod sursa(job #1182861)
| Utilizator | Data | 7 mai 2014 22:14:27 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <cstdio>
using namespace std;
int expo_log(long long int x,long long int n){
switch(n){
case 0: return 1; break;
case 1: return x; break;
}
if(n%2==0)
return expo_log(x*x,n/2);
else
return x*expo_log(x*x,(n-1)/2);
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long long int x,p;
scanf("%lld%lld",&x,&p);
printf("%d\n",expo_log(x,p)%1999999973);
return 0;
}
