#include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=5e4+5; int n,m,q; int a[N],b[N]; vector<tuple<int,int,int>>ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>q; for(int i=1;i<=q;++i){ int x;cin>>x,b[x]=1; } a[n]=1; for(int i=1;i<=n;++i)if(a[i]!=b[i]) if(b[i]){ ans.emplace_back(1,n+m,i),++m; for(int j=i;j<=n;j+=i)a[j]=1; } else{ ans.emplace_back(3,i,0),ans.emplace_back(2,n+m,n+m+1),m+=2; for(int j=i;j<=n;j+=i)a[j]=0; } cout<<ans.size()<<'\n'; for(auto [o,x,y]:ans) if(o==3)cout<<o<<' '<<x<<'\n'; else cout<<o<<' '<<x<<' '<<y<<'\n'; return 0; } /* */
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 | #include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; const int N=5e4+5; int n,m,q; int a[N],b[N]; vector<tuple<int,int,int>>ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>n>>q; for(int i=1;i<=q;++i){ int x;cin>>x,b[x]=1; } a[n]=1; for(int i=1;i<=n;++i)if(a[i]!=b[i]) if(b[i]){ ans.emplace_back(1,n+m,i),++m; for(int j=i;j<=n;j+=i)a[j]=1; } else{ ans.emplace_back(3,i,0),ans.emplace_back(2,n+m,n+m+1),m+=2; for(int j=i;j<=n;j+=i)a[j]=0; } cout<<ans.size()<<'\n'; for(auto [o,x,y]:ans) if(o==3)cout<<o<<' '<<x<<'\n'; else cout<<o<<' '<<x<<' '<<y<<'\n'; return 0; } /* */ |