You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 210;
|
|
int a[N], idx;
|
|
int n;
|
|
|
|
int main() {
|
|
cin >> n;
|
|
while (n > 1) {
|
|
a[idx++] = n;
|
|
if (n & 1)
|
|
n = n * 3 + 1;
|
|
else
|
|
n = n >> 1;
|
|
}
|
|
a[idx] = 1;
|
|
for (int i = idx; i >= 0; i--) printf("%d ", a[i]);
|
|
return 0;
|
|
} |