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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <bits/stdc++.h>

using namespace std;

enum OpType
{
    UNION = 1,
    INTERSECTION = 2,
    NEGATION = 3
};

struct Op
{
    int type, setA, setB;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    const int MAX_N = 50005;
    int n, s, i, j;
    cin >> n >> s;
    
    vector<int> targetSet(s);
    bitset<MAX_N> targetBits;
    for (i = 0; i < s; ++i)
    {
        cin >> targetSet[i];
        targetBits.set(targetSet[i]);
    }
    
    if (s == n)
    {
        cout << "1\n";
        cout << "1 1 1\n";
        return 0;
    }
    
    vector<Op> ops;
    
    vector<int> resSets;
    bitset<MAX_N> resBits;
    for (int x : targetSet)
    {
        bool go = false;
        for (i = x; i <= n; i += x)
        {
            if (targetBits.test(i) && !resBits.test(i))
            {
                go = true;
                break;
            }
        }
        
        if (!go)
        {
            continue;
        }
        
        vector<int> unionSets;
        vector<bool> removed(n + 1, false);
        
        for (i = x; i <= n; i += x)
        {
            if (removed[i] || targetBits.test(i))
            {
                if (!removed[i])
                {
                    resBits.set(i);
                }
                
                continue;
            }
            
            unionSets.push_back(i);
            for (j = 2 * i; j <= n; j += i)
            {
                removed[j] = true;
            }
        }
        
        if (unionSets.empty())
        {
            resSets.push_back(x);
            continue;
        }
        
        int currSet = unionSets[0];
        for (i = 1; i < (int) unionSets.size(); ++i)
        {
            ops.push_back({ UNION, currSet, unionSets[i] });
            currSet = n + ops.size();
        }
        
        ops.push_back({ NEGATION, currSet });
        currSet = n + ops.size();
        
        if (x != 1)
        {
            ops.push_back({ INTERSECTION, currSet, x });
            currSet = n + ops.size();
        }
        
        resSets.push_back(currSet);
    }
    
    assert(!resSets.empty());
    int currSet = resSets[0];
    if (resSets.size() == 1)
    {
        ops.push_back({ UNION, currSet, currSet });
    }
    else
    {
        for (i = 1; i < (int) resSets.size(); ++i)
        {
            int otherSet = resSets[i];
            ops.push_back({ UNION, currSet, otherSet });
            currSet = n + ops.size();
        }
    }
    
    assert((int) ops.size() <= 2 * n);
    cout << ops.size() << "\n";
    for (const auto& op : ops)
    {
        cout << op.type << " " << op.setA;
        if (op.type != 3)
        {
            cout << " " << op.setB;
        }
        cout << "\n";
    }
    
    return 0;
}