summaryrefslogtreecommitdiff
path: root/introductory_problems/weird_algorithm.cpp
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-12-17 13:18:18 -0700
committerJack Sangdahl <[email protected]>2024-12-17 13:18:18 -0700
commitbe030b74805f245c8618c77b03e76f16b3fc945a (patch)
tree9054d2c2b8ded0a404613a25c5b158cfbe02dc50 /introductory_problems/weird_algorithm.cpp
downloadcses-be030b74805f245c8618c77b03e76f16b3fc945a.tar.gz
cses-be030b74805f245c8618c77b03e76f16b3fc945a.zip
1608. weird algorithm
Diffstat (limited to 'introductory_problems/weird_algorithm.cpp')
-rw-r--r--introductory_problems/weird_algorithm.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/introductory_problems/weird_algorithm.cpp b/introductory_problems/weird_algorithm.cpp
new file mode 100644
index 0000000..d8f42c3
--- /dev/null
+++ b/introductory_problems/weird_algorithm.cpp
@@ -0,0 +1,13 @@
+// 1608. Weird Algorithm
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ long long num;
+ scanf("%lld", &num);
+ while (num > 1) {
+ printf("%lld ", num);
+ num = num & 1 ? 3 * num + 1 : num / 2;
+ }
+ printf("1\n");
+}