標題:
3n+1問題
[打印本頁]
作者:
李知易
時間:
7 天前 14:53
標題:
3n+1問題
本帖最後由 李知易 於 2025-4-12 15:27 編輯
c039. 00100 - The 3n + 1 problem
參考解答:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
while(cin >> a >> b)
{
int Max = 0;
for(int i = ((a<b)?a:b); i <= ((a>b)?a:b); i++)
{
int n = i, cot = 1;
while(n != 1)
{
if(n % 2 == 0) n /= 2;
else n = n * 3 + 1;
cot++;
}
Max = max(Max, cot);
}
cout << a << " " << b << " " << Max << endl;
}
return 0;
}
複製代碼
作者:
李穎俊
時間:
7 天前 14:54
此帖僅作者可見
作者:
洪榮辰
時間:
7 天前 15:03
此帖僅作者可見
作者:
張淯祺
時間:
7 天前 15:08
此帖僅作者可見
作者:
朱奕祈
時間:
7 天前 15:09
此帖僅作者可見
作者:
蔡宇庭
時間:
7 天前 15:09
此帖僅作者可見
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2