Daffodil International University
Problem Link
//Please follow from main function
#include<bits/stdc++.h>
using namespace std;
int main()
int l, c=1, i=1;
long long a;
while(cin>>a>>l)
{
c=1;
if(a<0 && l<0) break;
cout<<"Case "<<i<<": A = "<<a<<", limit = "<<l<<", number of terms = ";
while(a!=1){
if(a<=l){
if(a%2==0)
a=a/2;
else
a=3*a+1;
c++;
}
else{
c--;
break;
}
}
cout<<c<<endl;
i++;
}
return 0;
}
0 Comments