aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-29 16:15:04 +0800
committercrupest <crupest@outlook.com>2020-07-29 16:15:04 +0800
commit20eebd4b087d402ae21fe2a499a5582bc72a8834 (patch)
tree97c417a47c5eb9715e6898bcd515961e963f80e5
parenta29a4c81b33c1489013e30333c60bcdae3301f30 (diff)
downloadcrupest-20eebd4b087d402ae21fe2a499a5582bc72a8834.tar.gz
crupest-20eebd4b087d402ae21fe2a499a5582bc72a8834.tar.bz2
crupest-20eebd4b087d402ae21fe2a499a5582bc72a8834.zip
import(solutions): Add problem 343 .
-rw-r--r--works/solutions/cpp/343.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/works/solutions/cpp/343.cpp b/works/solutions/cpp/343.cpp
new file mode 100644
index 0000000..d31f7ce
--- /dev/null
+++ b/works/solutions/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));
+ }
+};