P5727 【深基5.例3】冰雹猜想

#include <bits/stdc++.h>

using namespace std;
const int N = 210;
int a[N], cnt;
int n;

int main() {
    cin >> n;
    while (n > 1) {
        a[cnt++] = n;
        if (n % 2 == 0) n /= 2;
        else n = n * 3 + 1;
    }
    //最后一个是1
    a[cnt] = 1;
    for (int i = cnt; i >= 0; i--)
        printf("%d ", a[i]);
    return 0;
}
posted @ 2021-11-10 15:05  糖豆爸爸  阅读(101)  评论(0编辑  收藏  举报
Live2D