Advertisement
mamamaria

1st task

Feb 4th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. pair<int,int> Kollatz(int n)
  5. {
  6.     pair <int, int> pairs;
  7.     int count3 = 0; int count2 = 0;
  8.     while (n != 1) {
  9.         if (n % 2 == 0) {
  10.             count2++;  n /= 2;
  11.         }
  12.         else { count3++; n = n * 3 + 1; }
  13.        
  14.     }
  15.     pairs.first = count2; pairs.second = count3;
  16.     return  pairs;
  17. }
  18. int main() {
  19.  
  20.     int N;
  21.     cin >> N;
  22.     int MULTI3 = 0; int DIV2 = 0;
  23.     _asm {
  24.         MOV EAX, N
  25.         MOV EDX, 0
  26.         MOV EBX, 2
  27.         MOV ECX, 3
  28.         A: CMP EAX, 1
  29.         JE B
  30.         BT EAX, 0
  31.         JNC C
  32.         JMP Q
  33.         C : DIV EBX
  34.         INC DIV2
  35.         JMP A
  36.         Q : MUL ECX
  37.         INC EAX
  38.         INC MULTI3
  39.         JMP A
  40.         B :
  41.     }
  42.     cout << DIV2 << "\t" << MULTI3;
  43.     cout << endl;
  44.     pair <int, int> pairs = Kollatz(N);
  45.     cout << pairs.first << "\t" << pairs.second;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement