18 lines
331 B
C++
18 lines
331 B
C++
#include "util.hpp"
|
|
|
|
namespace bigmath {
|
|
|
|
u64 ipow(u64 b, u64 p) {
|
|
// FROM stack overflow
|
|
// "The most efficient way to implement [int pow]"
|
|
u64 r = 1;
|
|
for(;;) {
|
|
if(p & 1) r *= b;
|
|
p >>= 1;
|
|
if(!p) break;
|
|
b *= b;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
} |