diff options
author | crupest <crupest@outlook.com> | 2020-07-29 16:15:04 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-29 16:15:04 +0800 |
commit | d991e6caf8c5b0eb2d0a5bd0679446b157233553 (patch) | |
tree | b087ac04d66c80a3a1a993d975d5e5746098d743 /cpp | |
parent | 7ed0906675d1a372bd3f0c32ca85bacfa911c617 (diff) | |
download | solutions-d991e6caf8c5b0eb2d0a5bd0679446b157233553.tar.gz solutions-d991e6caf8c5b0eb2d0a5bd0679446b157233553.tar.bz2 solutions-d991e6caf8c5b0eb2d0a5bd0679446b157233553.zip |
Add problem 343 .
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/343.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/cpp/343.cpp b/cpp/343.cpp new file mode 100644 index 0000000..d31f7ce --- /dev/null +++ b/cpp/343.cpp @@ -0,0 +1,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));
+ }
+};
|