#include <bits/stdc++.h> using namespace std; vector<bitset<50000>> tab; void fastscan(int &n){ n=0; for(char c=getchar();c>47 && c<58;c=getchar()){ n=10*n+c-48; } } vector<array<int,3>> ans; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,s; fastscan(n); fastscan(s); tab.resize(n); bitset<50000> target; for (int i = 1,x; i<=s; i++){ fastscan(x); target[x-1]=1; } for (int i = 1; i<=n; i++){ for (int j = i; j<=n; j+=i){ tab[i-1][j-1]=1; } } bitset<50000> now{}; ans.push_back({3,1,0}); int iter=n+1; for (int i = 1; i<=n; i++){ if (target[i-1]){ if (!now[i-1]){ ans.push_back({1,i,iter++}); now|=tab[i-1]; } } else{ if (now[i-1]){ ans.push_back({3,i,0}); ans.push_back({2,iter,iter+1}); iter+=2; now&=~tab[i-1]; } } } cout << ans.size() << '\n'; for (auto x : ans){ if (x[0]<3)cout << x[0] << ' ' << x[1] << ' ' << x[2] << '\n'; else cout << x[0] << ' ' << x[1] << '\n'; } }
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 | #include <bits/stdc++.h> using namespace std; vector<bitset<50000>> tab; void fastscan(int &n){ n=0; for(char c=getchar();c>47 && c<58;c=getchar()){ n=10*n+c-48; } } vector<array<int,3>> ans; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,s; fastscan(n); fastscan(s); tab.resize(n); bitset<50000> target; for (int i = 1,x; i<=s; i++){ fastscan(x); target[x-1]=1; } for (int i = 1; i<=n; i++){ for (int j = i; j<=n; j+=i){ tab[i-1][j-1]=1; } } bitset<50000> now{}; ans.push_back({3,1,0}); int iter=n+1; for (int i = 1; i<=n; i++){ if (target[i-1]){ if (!now[i-1]){ ans.push_back({1,i,iter++}); now|=tab[i-1]; } } else{ if (now[i-1]){ ans.push_back({3,i,0}); ans.push_back({2,iter,iter+1}); iter+=2; now&=~tab[i-1]; } } } cout << ans.size() << '\n'; for (auto x : ans){ if (x[0]<3)cout << x[0] << ' ' << x[1] << ' ' << x[2] << '\n'; else cout << x[0] << ' ' << x[1] << '\n'; } } |