P5727 Why not? Help!!
  • 板块题目总版
  • 楼主zhutongxuan
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/12/23 18:09
  • 上次更新2023/12/23 20:46:34
查看原帖
P5727 Why not? Help!!
1237323
zhutongxuan楼主2023/12/23 18:09

求助

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
	int n,ans[100000],i = 1;
	scanf("%d",&n);
	ans[0] = n;
	for(;;i++){
		if(ans[i - 1] % 2 == 0){
			ans[i] = ans[i - 1] / 2;
		}
		else{
			ans[i] = ans[i - 1] * 3 + 1;
		}
		if(ans[i] == 1){
			break;
		}
	}
	for(int j = i;j >= 0;j--){
		cout<<ans[j]<<" ";
	}
	cout<<endl;
	return 0;
}
2023/12/23 18:09
加载中...