I submit my answer in Programming Challenges Judge(here
http://www.programming-challenges.com[
^]).I think my code of my is correct,but it show the result that is Answer Wrong.
Here is the code:
#include "stdafx.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
unsigned int NumOfSquence(unsigned int n);
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int i = 1,j = 1,temp = 0;
cin>>i>>j;
if(i > j){
temp = i;
i = j;
j = temp;
}
unsigned int max = NumOfSquence(i);
for(unsigned int k = i + 1;k <= j; k++){
temp = NumOfSquence(k);
if(temp > max){
max = temp;
}
}
cout<<i<<" "<<j<<" "<<max<<endl;
return 0;
}
unsigned int NumOfSquence(unsigned int n){
unsigned int num = 1;
while(n != 1){
if(n % 2 == 0){
n /=2;
}
else if(n % 2 == 1){
n = 3 * n + 1;
}
num++;
}
return num;
}