1 #include <common/math.h> 2 #include <common/stddef.h> 3 4 int64_t pow(int64_t x, int y) 5 { 6 if (y == 0) 7 return 1; 8 if (y == 1) 9 return x; 10 if (y == 2) 11 return x * x; 12 int64_t res = 1; 13 while (y != 0) 14 { 15 if (y & 1) 16 res *= x; 17 y >>= 1; 18 x *= x; 19 } 20 return res; 21 }