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
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    int n, s;
    cin >> n >> s;
    
    set<int> zbior_docelowy;
    for (int i = 0; i < s; i++) {
        int x;
        cin >> x;
        zbior_docelowy.insert(x);
    }

    vector<pair<int, pair<int, int>>> operacje;
    vector<set<int>> zbiory(n + 1);

    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            zbiory[i].insert(j);
        }
    }

    int indeks = n + 1;
    for (int i = 1; i <= n; i++) {
        if (zbiory[i] == zbior_docelowy) {
            cout << "0\n";
            return 0;
        }
    }

    int a = 1, b = 2;
    set<int> suma;
    suma.insert(zbiory[a].begin(), zbiory[a].end());
    suma.insert(zbiory[b].begin(), zbiory[b].end());

    operacje.push_back({1, {a, b}});
    zbiory.push_back(suma);

    if (suma == zbior_docelowy) {
        cout << operacje.size() << "\n";
        for (auto &op : operacje) {
            cout << op.first << " " << op.second.first << " " << op.second.second << "\n";
        }
        return 0;
    }

    cout << "-1\n";
    return 0;
}