JosepRivaille

P14410: Siracusa ataca de nou

Apr 9th, 2015
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void convergeix(int n, int& k, int& lluny) {
  6.     int p = k;
  7.     for (int i = 1; i <= n; ++i) {
  8.         k = 0;
  9.         int j = i;
  10.         while (j != 1) {
  11.             if (j > lluny) lluny = j;
  12.             if (j%2 == 0) j = j/2;
  13.             else j = 3*j + 1;
  14.             ++k;
  15.         }
  16.         if (k >= p) cout << i << endl;
  17.     }
  18.     cout << "S'arriba a " << lluny << '.' << endl;
  19. }
  20.  
  21. int main() {
  22.     int n, p;
  23.     cin >> n >> p;
  24.     int k = p;
  25.     int lluny = 1;
  26.     convergeix(n, k, lluny);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment