i থেকে j এর মধ্যে জতগুল নাম্বার আছে তাদের প্রতিটির সাইকেল লেন্থ বের করতে হবে i এবং j সহ, এদের মধ্যে সর্বচ cycle length বের করতে হবে।
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------------------------------*/ | |
//Uva Problem Name : 3n+1 | |
//Uva Problem No: 100 | |
//Author : shohanur Rahaman | |
//University : City university | |
//E-mail : shohan4556@gmail.com | |
/*-----------------------------------------------*/ | |
#include<stdio.h> | |
int main() | |
{ | |
int count,i,n1,n2,j,max=0,tmp,mairala=0; | |
while(scanf("%d %d",&n1,&n2)==2){ // assume that n1 is greater than n2 | |
printf("%d %d ",n1,n2); | |
if(n1<n2){ // if not swap both number | |
tmp=n2; | |
n2=n1; | |
n1=tmp; | |
} | |
max=0; | |
for(i=n2;i<=n1;i++){ | |
count=1; | |
mairala=i; | |
while(mairala>1){ | |
if(mairala%2!=0) | |
mairala=3*mairala+1; | |
else | |
mairala=mairala/2; | |
count++; | |
} | |
if(count>=max) | |
max=count; | |
} | |
printf("%d\n",max); | |
} | |
return 0; | |
} |