#30082: c


jojojo22845@gmail.com (lu)

學校 : 國立臺灣大學
編號 : 190663
來源 : [140.112.229.2]
最後登入時間 :
2023-06-07 10:38:04
c039. 00100 - The 3n + 1 problem -- UVa100 | From: [163.32.125.90] | 發表日期 : 2022-04-27 09:56

#include<stdio.h>

int countNumber(int i){
int count = 1;
while(i != 1){
if(i % 2 == 0){
i = i / 2;
count++;
}
else{
i = 3 * i + 1;
count++;
}
}
return count;
}

void swap(int *i, int *j){
int temp = *i;
*i = *j;
*j = temp;
}

int main(){
int i = 0, j = 0;
while(scanf("%d %d",&i, &j) != EOF){
printf("%d %d ",i ,j);
if(i >= j){
swap(&i, &j);
}
int max= 0;
for (int k = i; k <= j; k++)
{
if(countNumber(k) > max){
max = countNumber(k);
}
}
printf("%d\n", max);
}
return 0;
}
 
ZeroJudge Forum