1005 继续(3n+1)猜想 (25 分)

#include
#include


int x[200] = {0};
int half(int a) {
    int count = 0;
    while (a > 1)
    {
        if (a % 2 == 1)
            a = (a * 3 + 1) / 2;
        else
            a /= 2;
        if (a < 200)x[a] = 0;
    }
    return count;
}
int main() {
    int n, in;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &in);
        x[in] = 1;
    }
    for (int i = 101; i >= 0; i--) {
        if (x[i])half(i);
    }
    int flag = 1;
    for (int i = 101; i >= 0; i--) {
        if (x[i]) {
            if (flag) {
                printf("%d", i); flag = 0;
            }
            else {
                printf(" %d", i);
            }
        }
    }
    return 0;
}

你可能感兴趣的:(1005 继续(3n+1)猜想 (25 分))