Vladislav_Bezruk

Some task

Oct 12th, 2020 (edited)
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long i,j,x,m,n,k,q;
  4.  
  5. int main() {
  6.    
  7.     m = 0;
  8.    
  9.     scanf("%li %li",&i,&j);
  10.    
  11.     if (i > j) {
  12.        
  13.     q =i ;
  14.     i = j;
  15.     j = q;
  16.            
  17.     }
  18.    
  19.     for (x = i;x < j+1;x++) {
  20.        
  21.     k = 0;
  22.     n = x; 
  23.        
  24.     while (n != 1) {
  25.        
  26.     k+=1;  
  27.    
  28.     if (n % 2 == 0) {
  29.        
  30.         n = n/2;
  31.        
  32.     }
  33.     else
  34.     {
  35.        
  36.     n = 3*n+1; 
  37.        
  38.     }
  39.                
  40.     }  
  41.     k+=1;
  42.     if (k>m) {
  43.        
  44.     m = k; 
  45.    
  46.     }
  47.  
  48.     }
  49.    
  50.      printf("%li %li %li\n",i,j,m);
  51.      
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment