Pat 继续3N+1
作者:
cloudann
,
2021-05-10 23:50:12
,
所有人可见
,
阅读 332
#include <iostream>
using namespace std;
bool important[110];
bool bit[int(1e8)];
int num[110];
int main(){
int n,j;
cin>>n;
for(int i = 0;i<n;i++){
cin>>num[i];
important[num[i]] = true;
}
for(int i = 0;i<n;i++){
if(bit[num[i]]){
num[i] = 0;
continue;
}
j = num[i];
while(!bit[j]){
bit[j] = 1;
j = j&1?(3*j+1):j;
j>>=1;
//cout<<j<<" ";
if(j<=100)
important[j] = 0;
}
//cout<<endl;
}
int i = 101;
while(!important[--i]);
cout<<i--;
for(;i>1;i--){
if(important[i])
cout<<" "<<i;
}
return 0;
}