3n+1不在100以内,开数组要大
#include<iostream>
using namespace std;
const int n=10000;
bool _prev[n],_next[n],exist[n];
void setnode(int x){
if((1==x)||_next[x])return;
int tmp=( (x%2)? ((3*x+1)/2) : (x/2) );
_prev[tmp]=true;
_next[x]=true;
setnode(tmp);
}
void process(){
int k,x;cin>>k;
while(k--){
cin>>x;
exist[x]=true;
setnode(x);
}
bool flag=true;
for(int i=n;i>1;--i)
if(exist[i]&&!_prev[i]){
if(flag){cout<<i;flag=false;}
else cout<<' '<<i;}
}
int main(){
process();
return 0;}