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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

const int MAX_N = 50005;
const int MAX_SIZE = 100005;

struct operation
{
	int type, x, y;
};

vector<bitset<MAX_N>> sets;
bitset<MAX_N> b;

int n, s, bi;
int m = 1;

vector<operation> ops;

void initNSets()
{
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i; j <= n; j += i)
		{
			sets[i][j] = 1;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> s;

	sets = vector<bitset<MAX_N>>(n + 1, bitset<MAX_N>());
	initNSets();

	for (int i = 0; i < s; ++i)
	{
		cin >> bi;
		b[bi] = 1;
	}

	if (b == *sets.rbegin())
	{
		cout << 0 << endl;
		return 0;
	}

	ops.push_back({ 3, 1, 0 });
	sets.push_back(bitset<MAX_N>());

	for (int i = 1; i <= n; ++i)
	{
		if (b[i] == (*sets.crbegin())[i])
		{
			continue;
		}

		if (b[i])
		{
			ops.push_back({ 1, i, static_cast<int>(sets.size()) - 1 });
			sets.push_back((*sets.crbegin()) | sets[i]);
		}
		else
		{
			ops.push_back({ 3, i, 0 });
			sets.push_back(~sets[i]);

			ops.push_back({ 2, static_cast<int>(sets.size()) - 2, static_cast<int>(sets.size()) - 1 });
			sets.push_back(sets[sets.size() - 2] & sets[sets.size() - 1]);
		}
	}

	cout << ops.size() << endl;
	for (const auto& oper : ops)
	{
		cout << oper.type << ' ' << oper.x << ' ';
		if (oper.type != 3)
		{
			cout << oper.y;
		}
		cout << endl;
	}

	return 0;
}