#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, s; cin >> n >> s; vector<int>T(n+1), B(n+1); rep(i, s) { int x; cin >> x; B[x]=1; } vector<string>ans; rep(i, n) ans.pb("3 " + to_string(i+1)); if(B[1]) { ans.pb("3 " + to_string(n+1)); rep(i, n) T[i+1]=1; } else { ans.pb("3 1"); } int lst=2*n+1; for(int i=2; i<=n; ++i) { if(T[i] && !B[i]) { ans.pb("2 " + to_string(lst) + " " + to_string(n+i)); for(int j=i; j<=n; j+=i) { T[j]=0; } ++lst; } else if(!T[i] && B[i]) { ans.pb("1 " + to_string(lst) + " " + to_string(i)); for(int j=i; j<=n; j+=i) { T[j]=1; } ++lst; } } cout << ans.size() << '\n'; for(auto i : ans) cout << i << '\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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, s; cin >> n >> s; vector<int>T(n+1), B(n+1); rep(i, s) { int x; cin >> x; B[x]=1; } vector<string>ans; rep(i, n) ans.pb("3 " + to_string(i+1)); if(B[1]) { ans.pb("3 " + to_string(n+1)); rep(i, n) T[i+1]=1; } else { ans.pb("3 1"); } int lst=2*n+1; for(int i=2; i<=n; ++i) { if(T[i] && !B[i]) { ans.pb("2 " + to_string(lst) + " " + to_string(n+i)); for(int j=i; j<=n; j+=i) { T[j]=0; } ++lst; } else if(!T[i] && B[i]) { ans.pb("1 " + to_string(lst) + " " + to_string(i)); for(int j=i; j<=n; j+=i) { T[j]=1; } ++lst; } } cout << ans.size() << '\n'; for(auto i : ans) cout << i << '\n'; } |