msiamn

UVa 100 - The 3n+1 problem

May 18th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1.  /***********************************************************************\  
  2.  |*********S***  ****** ************* ************ **************  ******|  
  3.  |***********  ******** ************  ************  *********** ** ******|  
  4.  |*********  ********** *********** *** ********** * ********* *** ******|  
  5.  |********  *********** *I******** **** ********** *** ***** ***** ******|  
  6.  |********  *********** ********* ****** ********* ***** ** ****** ******|  
  7.  |**********  ********* ******** ***A**** ******** ******* ******* ******|  
  8.  |***********  ******** ******* ********** ******* *************** ******|  
  9.  |**********  ********* ****** ************ ****** *************** ******|  
  10.  |********  *********** ***** ************** ***** ********M****** ******|  
  11.  |*****  ************** **** **************** **** *************** ******|  
  12.  |***********************************************************************|  
  13.  |**************BSMRSTU********************************CSE***************|  
  14.  \***********************************************************************/  
  15.  #include<stdio.h>  
  16.  #include<string.h>  
  17.  #include<math.h>  
  18.  #include<conio.h>  
  19.  #include<stdlib.h>  
  20.  #define ll long long  
  21.  #define B break  
  22.  #define C continue  
  23.  #define sf scanf  
  24.  #define pf printf  
  25.  #define byebye return 0  
  26.  int main()  
  27.  {  
  28.    int a,b;  
  29.    while(sf("%d%d",&a,&b)!=EOF)  
  30.    {  
  31.      pf("%d %d",a,b);  
  32.      if(a>b){  
  33.        int n=a;  
  34.        a=b;  
  35.        b=n;  
  36.      }  
  37.      int i,j,total=0;  
  38.      for(i=a; i<=b; i++)  
  39.      {  
  40.        int count=1;  
  41.        j=i;  
  42.        while(j!=1)  
  43.        {  
  44.          if(j%2)  
  45.          {  
  46.            j=(3*j)+1;  
  47.          }  
  48.          else  
  49.          {  
  50.            j=j/2;  
  51.          }  
  52.          count++;  
  53.        }  
  54.        if(total<count)  
  55.          total=count;  
  56.      }  
  57.      pf(" %d\n",total);  
  58.    }  
  59.    byebye;  
  60.  }
Advertisement
Add Comment
Please, Sign In to add comment