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 | 5b771a8dbf9a0867af6fb7e394cdba1893985b47 (patch) | |
tree | 725450d325e67ec6ce6c223f7e6c8d67df4358e6 /works/solutions/cpp | |
parent | cea61f4f4e8b2d4df882369a265a268e5c09f480 (diff) | |
download | crupest-5b771a8dbf9a0867af6fb7e394cdba1893985b47.tar.gz crupest-5b771a8dbf9a0867af6fb7e394cdba1893985b47.tar.bz2 crupest-5b771a8dbf9a0867af6fb7e394cdba1893985b47.zip |
import(solutions): Add problem 343 .
Diffstat (limited to 'works/solutions/cpp')
-rw-r--r-- | works/solutions/cpp/343.cpp | 23 |
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));
+ }
+};
|