#include <cstdio>
#include <vector>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define SIZE(c) ((int)(c).size())
#define INT(x) int x; scanf("%d", &x)
bool a[50001], b[50001];
struct Op {
Op(int o, int x, int y) : o(o), x(x), y(y) {}
int o, x, y;
};
vector<Op> r;
int main() {
INT(n);
INT(s);
REP(ss,s) {
INT(bb);
b[bb] = 1;
}
bool first = 1;
FOR(i,1,n+1) {
if (a[i] == b[i]) continue;
int last = n + SIZE(r);
if (b[i]) {
if (first) {
first = 0;
last = i;
}
r.PB(Op(1, last, i));
for (int j = i; j <= n; j += i)
a[j] = 1;
} else {
r.PB(Op(3, i, 0));
r.PB(Op(2, last, last + 1));
for (int j = i; j <= n; j += i)
a[j] = 0;
}
}
printf("%d\n", SIZE(r));
FORE(it,r) {
if (it->o == 3) printf("%d %d\n", it->o, it->x);
else printf("%d %d %d\n", it->o, it->x, it->y);
}
}
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 <cstdio> #include <vector> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define VAR(v,w) __typeof(w) v=(w) #define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it) #define PB push_back #define SIZE(c) ((int)(c).size()) #define INT(x) int x; scanf("%d", &x) bool a[50001], b[50001]; struct Op { Op(int o, int x, int y) : o(o), x(x), y(y) {} int o, x, y; }; vector<Op> r; int main() { INT(n); INT(s); REP(ss,s) { INT(bb); b[bb] = 1; } bool first = 1; FOR(i,1,n+1) { if (a[i] == b[i]) continue; int last = n + SIZE(r); if (b[i]) { if (first) { first = 0; last = i; } r.PB(Op(1, last, i)); for (int j = i; j <= n; j += i) a[j] = 1; } else { r.PB(Op(3, i, 0)); r.PB(Op(2, last, last + 1)); for (int j = i; j <= n; j += i) a[j] = 0; } } printf("%d\n", SIZE(r)); FORE(it,r) { if (it->o == 3) printf("%d %d\n", it->o, it->x); else printf("%d %d %d\n", it->o, it->x, it->y); } } |
English