-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.cpp
More file actions
42 lines (33 loc) · 762 Bytes
/
src.cpp
File metadata and controls
42 lines (33 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
void hanoi(int n, int start, int by, int dest);
string BigInteger(double val);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
cout << BigInteger(pow(2, N)) << '\n';
if (N <= 20)
hanoi(N, 1, 2, 3);
return 0;
}
string BigInteger(double val) {
string answer = to_string(val);
answer = answer.substr(0, answer.find('.'));
answer[answer.size() - 1] -= 1;
return answer;
}
void hanoi(int n, int start, int by, int dest) {
if (n == 1) {
cout << start << ' ' << dest << '\n';
return;
}
hanoi(n - 1, start, dest, by);
cout << start << ' ' << dest << '\n';
hanoi(n - 1, by, start, dest);
}