• Source
    1. /// Author : Shohanur Rahaman
    2. /// URI : 1441
    3.  
    4. #include <iostream>
    5. #include<stdio.h>
    6.  
    7. using namespace std;
    8.  
    9. int ev=0,od=0;
    10. int even(int n);
    11. int odd(int n);
    12. int even_odd_chcek(int n);
    13.  
    14. int main()
    15. {
    16. int n,t,a,ans;
    17. int max;
    18.  
    19. while(scanf("%d",&n)==1){
    20.  
    21. if(n==0)
    22. break;
    23.  
    24. t=n;
    25. max=n; // because if n even then max would be the number n=32 then 32,16,8,4,2,1
    26. // here max is 32 I mean n
    27. while(t!=1){
    28.  
    29. if(even_odd_chcek(t)==1){ //odd
    30. t=odd(t);
    31. a=t;
    32. if(a>max){
    33. max=a;
    34. }
    35. }
    36.  
    37. if(even_odd_chcek(t)==0){ //even
    38. t=even(t);
    39. a=t;
    40.  
    41. if(a>max){
    42. max=a;
    43. }
    44. }
    45.  
    46. } // end child loop
    47.  
    48. printf("%d\n",max);
    49.  
    50. } // end parent loop
    51.  
    52. return 0;
    53. }
    54.  
    55. int even(int n)
    56. {
    57. int tmp=n/2;
    58. return tmp;
    59. }
    60.  
    61. int odd(int n)
    62. {
    63. int tmp=0;
    64. tmp=(n*3)+1;
    65.  
    66. return tmp;
    67. }
    68.  
    69. int even_odd_chcek(int n){
    70.  
    71. if(n%2==0){
    72. ev=0;
    73. return ev;
    74. }
    75. else{
    76. od=1;
    77. return od;
    78. }
    79. }
    80.  
    81.  
    82.  
    83.  
    84.