/***
Md. Namzul Hasan
Shahjalal University of Sciency & technology,sylhet.
hasan08sust@gmail.com
verdict:
***/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<sstream>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
int main()
{
vector<in> jak ;
ll m, n,i,k,p,v,count ;
while(cin>>m>>n && m&& n)
{
if(m>n)
swap(m,n) ;
p =0 ;
for(i =m ; i<=n;i++)
{
k = i ;
count =0 ;
while(1)
{
if(k%2!=0)
k = (3*k)+1 ;
else
k = k/2 ;
count++ ;
if(k==1)
break ;
}
if(p<count)
{
p = count ;
v = i ;
}
}
pf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",m,n,v,p) ;
}
return 0 ;
}
Md. Namzul Hasan
Shahjalal University of Sciency & technology,sylhet.
hasan08sust@gmail.com
verdict:
***/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<sstream>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
int main()
{
vector<in> jak ;
ll m, n,i,k,p,v,count ;
while(cin>>m>>n && m&& n)
{
if(m>n)
swap(m,n) ;
p =0 ;
for(i =m ; i<=n;i++)
{
k = i ;
count =0 ;
while(1)
{
if(k%2!=0)
k = (3*k)+1 ;
else
k = k/2 ;
count++ ;
if(k==1)
break ;
}
if(p<count)
{
p = count ;
v = i ;
}
}
pf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",m,n,v,p) ;
}
return 0 ;
}
No comments:
Post a Comment