3n+1Problem/김태진 (rev. 1.1)
Status ¶
Memory | 164K | Time | 0MS |
개발시간: 1시간, 입출력문제->1시간 |
Source Code ¶
#include <stdio.h>
int main()
{
int i,j,max=0,n=1,k,b,c;
unsigned int a=0;
int A[10000]={0};
while(1){
scanf("%d",&b);
scanf("%d",&c);
if(b>c) {j=c; k=b;}
else {j=b; k=c;}
// 조건?참일경우:거짓일경우;
for(i=j;i<=k;i++){
a=i;
while(1){
if(a==1) break;
if(a<i&&a>j) {n=A[i]; break;}
if(a%2==1) {a=(3*a+1)>>1; n++;}
else a=a>>1;
n++;
}
A[i]=n; //DP만드는중
if(max<n) max=n;
n=1;
}
if(feof(stdin)) break;
printf("%d %d %d\n",b,c,max);
max=0;
}
return 0;
}