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
#include <iostream>
#include <vector>
#include <bitset>
#include <unordered_set>
#include <string>
#include <sstream>

const int MAX_N = 50000;

int main() {
    int n, m;
    std::cin >> n >> m;
    
    std::bitset<MAX_N + 1> myNumber;
    std::unordered_set<int> hashSet;
    std::ostringstream result;
    for (int i = 1; i <= m; i++) {
        int x;
        std::cin >> x;
        hashSet.insert(x);
    }

    int counter = 0;
    int tempIterator = 1;
    myNumber.set();

    for (int i = 1; i <= n; i++) {
        //mam w mojej liczbie, ale nie mam w hashSet
        if(hashSet.count(i) == 0 && myNumber[i] == 1) {          
          result << "3 " << i << "\n";
          counter++;
          if(counter > 1)
          {
            result << "2 " << (counter + n-1) << " " << (counter + n) << "\n";
          }
          else{
            result << "2 " << 1 << " " << (counter + n) << "\n";
          }
          counter++;

          int temp = i;
            while(temp <= n) {
                myNumber[temp] = 0;
                temp += i;
            }
        }
        //nie mam w mojej liczbie, ale mam w hashSet
        else if(hashSet.count(i) > 0 && myNumber[i] == 0) {
            result << "1 " << i << " " << (counter + n) << "\n";
            counter++;

            int temp = i;
            while(temp <= n) {
                myNumber[temp] = 1;
                temp += i;
            }
        }
    }

    std::cout << counter << std::endl;
    std::cout << result.str() << std::endl;

    return 0;
}