-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSolution.cpp
More file actions
45 lines (39 loc) · 815 Bytes
/
Solution.cpp
File metadata and controls
45 lines (39 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
class Solution {
public:
// 2 <= n <= 58
int integerBreak(int n) {
if (n == 2) return 1;
if (n == 3) return 2;
if (n == 4) return 4;
int n3 = 0;
while (n >= 5) {
n3 ++ ;
n -= 3;
}
return fast_pow(3, n3) * n;
}
int fast_pow(int x, int y) {
int res = 1;
for (int offset = sizeof(int) * 8 - 1; offset >= 0; offset --) {
res *= res;
if (y & (1 << offset)) res *= x;
}
return res;
}
};
int main() {
Solution a;
return 0;
}