O(1)
| 52 | |
| 53 | // O(1) |
| 54 | unsigned long pow(unsigned long x, unsigned int y) { |
| 55 | // bitwise traverse y |
| 56 | unsigned long res = 1; |
| 57 | for (int offset = sizeof(int) * 8 - 1; offset >= 0; offset --) { |
| 58 | res *= res; // right shift |
| 59 | if (y & (1 << offset)) res *= x; |
| 60 | } |
| 61 | return res; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | int main() { |
no outgoing calls
no test coverage detected