Cod sursa(job #612022)
| Utilizator | Data | 5 septembrie 2011 15:04:18 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include<stdio.h>
long exponentiere(int x, unsigned long n) {
if(n==0) return 1;
if(n%2!=0)
return x*exponentiere(x,(n-1)/2)*exponentiere(x,(n-1)/2);
else
return exponentiere(x,n/2)*exponentiere(x,n/2);
}
void main() {
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int nr;
unsigned long put, rez, mod=1999999973;
scanf("%i",&nr);
//printf("%i\n",nr);
scanf("%lu",&put);
//printf("%lu\n",put);
rez = exponentiere(nr,put);
printf("%lu\n",(rez%mod));
}
