Platinum Partner

ACM Q100: The 3n + 1 Problem

// description of your code here


// insert code here..
#include 

void cal(int m , int n ){

   int k ;
       int num , times=1 ;
       int MAX = 0 ;

       for( k = m ; k <= n ; k++ ){
           num = k ;
               while( num != 1){
                       if( num % 2 == 0 ) {
                               num /= 2;
                       }
                       else {
                               num = 3*num+1 ;
                       }
                       times ++ ;
       }
               if(times > MAX){
                   MAX = times ;
               }
               times = 1 ;
       }

       printf("%d\n", MAX ) ;

}

int main() {

       int i , j ;

       while((scanf( "%d%d" , &i , &j ))==2){

       printf("%d %d ", i , j ) ;

       if( i < j ) {
           cal( i , j ) ;
       }
       else{
           cal( j , i ) ;
       }
       }

       return 0;
}

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}