| 12 | using namespace std; |
| 13 | |
| 14 | class Solution { |
| 15 | public: |
| 16 | // 2 <= n <= 58 |
| 17 | int integerBreak(int n) { |
| 18 | if (n == 2) return 1; |
| 19 | if (n == 3) return 2; |
| 20 | if (n == 4) return 4; |
| 21 | int n3 = 0; |
| 22 | while (n >= 5) { |
| 23 | n3 ++ ; |
| 24 | n -= 3; |
| 25 | } |
| 26 | return fast_pow(3, n3) * n; |
| 27 | } |
| 28 | |
| 29 | int fast_pow(int x, int y) { |
| 30 | int res = 1; |
| 31 | for (int offset = sizeof(int) * 8 - 1; offset >= 0; offset --) { |
| 32 | res *= res; |
| 33 | if (y & (1 << offset)) res *= x; |
| 34 | } |
| 35 | return res; |
| 36 | } |
| 37 | |
| 38 | }; |
| 39 | |
| 40 | int main() { |
| 41 | Solution a; |
nothing calls this directly
no outgoing calls
no test coverage detected