unsigned long long rpow(int n, int p) {
return p ? p==1 ? n : n * rpow(n,p-1) : 1;
}
int main(int argc, char **argv) {
if(argv[1])
if(argv[2]) {
int n = atoi(argv[1]);
int p = atoi(argv[2]);
printf("%llu\n",rpow(n,p));
}
return 0;
}
Name:
Anonymous2009-03-12 17:34
>>128
Wrong.
A 32 bit integer pow library could run in constant (amortized) time if you had the neccesary memory to store lookup tables of all the results, and the means with which to distribute the somewhat large source/compiled code. Then again, it would be very easy and small to store if done with self modifying code or code that generates the code needed, then compiles and dynamically includes that, but then you would have an obscenely large load time followed by constant time pow calculations. Obviously this would be less practical to attempt with 64 bit or higher machines.