/* Question 3: The 3N + 1 problem (PKU 1207)
* Author: Guo fengzai
*/
# Include <cstdio>
Using namespace STD;
Int main (){
Int X, Y;
While (scanf ("% d", & X, & Y )! = EOF ){
// While (CIN> x> Y ){
Int X1 = x, Y1 = y;
Int maxlength = 1; // maximum cycle length.
If (x1> Y1) {// The input may be large to small, but the order cannot be changed during output. Therefore, two alternative variables are declared.
Int T = x1;
X1 = Y1;
Y1 = T;
}
For (INT I = x1; I <= Y1; ++ I ){
Int temp = I;
Int length = 1; // The cycle length of each integer.
While (temp! = 1 ){
If (TEMP % 2 = 1 ){
Temp = 3 * temp + 1;
} Else {
Temp = temp/2;
}
++ Length;
}
Maxlength = maxlength> length? Maxlength: length; // store large objects in maxlength.
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.