U E D R , A S I H C RSS

3N+1 Problem/김회영

~cpp 
//1. 3n+1  [[[[AOI]]]]  
 
#include<iostream.h> 
 
int check(int n); 
 
void main() 
{ 
        int n1;    // 1 
        int n2;    // 2 
        int max=0; //  .  
        cout<<"    ( .n1<n2 )"<<endl; 
        cin>>n1; 
        cin.get(); 
        cin>>n2; 
        int temp = n2; 
         
        for(int i= n2-n1 ; i >=0 ; i--) 
        { 
                if(check(temp)>max) 
                        max = check(temp); 
                temp--; 
        } 
         
        cout<<""<<n1<<""<<n2<<"  "<<max<<"."<<endl; 
} 
 
int check(int n)//   
{ 
        int count = 1;//       
         
        while(n!=1) 
        { 
                int temp = n%2; 
                 
                if(temp==0)//temp ..  
                        n = n/2; 
                else //temp .. 
                        n = ((3*n)+1); 
         
                count++; 
        } 
 
return count; 
} 
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:16
Processing time 0.0122 sec