aboutsummaryrefslogtreecommitdiff
path: root/cses/WeirdAlgorithm/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cses/WeirdAlgorithm/main.cpp')
-rw-r--r--cses/WeirdAlgorithm/main.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/cses/WeirdAlgorithm/main.cpp b/cses/WeirdAlgorithm/main.cpp
new file mode 100644
index 0000000..ab5b099
--- /dev/null
+++ b/cses/WeirdAlgorithm/main.cpp
@@ -0,0 +1,19 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ long long n;
+ cin >> n;
+ while (n != 1) {
+ cout << n << " ";
+ if (n % 2 == 0) {
+ n /= 2;
+ } else {
+ n = n * 3 + 1;
+ }
+ }
+ cout << 1;
+}