blob: d31f7ce031d558ba9d119358b9441f100279deb8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <cmath>
class Solution
{
public:
int integerBreak(int n)
{
if (n == 2)
return 1;
if (n == 3)
return 2;
if (n % 3 == 1)
{
return static_cast<int>(std::pow(3, n / 3 - 1)) * 4;
}
else if (n % 3 == 2)
{
return static_cast<int>(std::pow(3, n / 3)) * 2;
}
return static_cast<int>(std::pow(3, n / 3));
}
};
|