Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- pair<int,int> Kollatz(int n)
- {
- pair <int, int> pairs;
- int count3 = 0; int count2 = 0;
- while (n != 1) {
- if (n % 2 == 0) {
- count2++; n /= 2;
- }
- else { count3++; n = n * 3 + 1; }
- }
- pairs.first = count2; pairs.second = count3;
- return pairs;
- }
- int main() {
- int N;
- cin >> N;
- int MULTI3 = 0; int DIV2 = 0;
- _asm {
- MOV EAX, N
- MOV EDX, 0
- MOV EBX, 2
- MOV ECX, 3
- A: CMP EAX, 1
- JE B
- BT EAX, 0
- JNC C
- JMP Q
- C : DIV EBX
- INC DIV2
- JMP A
- Q : MUL ECX
- INC EAX
- INC MULTI3
- JMP A
- B :
- }
- cout << DIV2 << "\t" << MULTI3;
- cout << endl;
- pair <int, int> pairs = Kollatz(N);
- cout << pairs.first << "\t" << pairs.second;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement