MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / Solution

Class Solution

343. Integer Break/Solution.cpp:14–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace std;
13
14class Solution {
15public:
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
40int main() {
41 Solution a;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected