Guest User

Untitled

a guest
Sep 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <stdint.h>
  4.  
  5. using namespace std;
  6.  
  7. uint32_t coll(uint32_t n) {
  8.   uint32_t k = 1;
  9.   while (n != 1) {
  10.     n = (n % 2) ? 3 * n + 1 : n / 2;
  11.     k += 1;
  12.   }
  13.   return k;
  14. }
  15.  
  16. int main(void) {
  17.   uint32_t i, j;
  18.  
  19.   while (cin >> i) {
  20.     cin >> j;
  21.     if (i > j) {
  22.       uint32_t tmp = i;
  23.       i = j;
  24.       j = tmp;
  25.     }
  26.     uint32_t now = i, m = 0;
  27.     while (now <= j) {
  28.       uint32_t tmp = coll(now);
  29.       if (tmp > m) {
  30.         m = tmp;
  31.       }
  32.       ++now;
  33.     }
  34.     printf("%u %u %u\n", i, j, m);
  35.   }
  36.   return 0;
  37. }
Add Comment
Please, Sign In to add comment