A
那么对于最小得k就是(g-a1%g)%g 注意要排序
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+50; ll a[N]; int main(){ int n;cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); ll gcd=0; for(int i=2;i<=n;i++) gcd=__gcd(gcd,a[i]-a[i-1]); cout<<gcd<<" "<<(gcd-a[1]%gcd)%gcd<<endl; return 0; }
B
#include<bits/stdc++.h> using namespace std; const int N=1e5+50; int a[N],ans[N]; int main(){ int n;cin>>n; int ma=0; for(int i=1;i<=n;i++){ int x;cin>>x; a[x]++; ma=max(ma,x); } for(int i=2;i<=n;i++) ans[i]=1; int last=2; for(int i=ma;i;i--){ int cnt=0; for(int j=i;j<=ma;j+=i){ cnt+=a[j]; } for(int j=last;j<=cnt;j++) ans[j]=i; last=max(last,cnt+1); } for(int i=2;i<=n;i++) cout<<ans[i]<<" "; return 0; }
C
#include<bits/stdc++.h> using namespace std; const int N=1e3+50; bitset<N>a[N],b[N]; bool vis[N][N]; int n,m1,m2,q; int main(){ cin>>n>>m1>>m2>>q; for(int i=1;i<=n;i++) a[i][i]=1; for(int i=1;i<=m1;i++){ int x,y;cin>>x>>y; a[x][y]=1; } for(int i=1;i<=m2;i++){ int x,y;cin>>x>>y; vis[x][y]=1; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(!vis[i][j]){ b[i][j]=1; } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(a[j][i]) a[j] |= a[i]; if(b[j][i]) b[j] |= b[i]; } } while(q--){ int x,y;cin>>x>>y; if(a[x][y]) cout<<"Yes "; else cout<<"No "; if(b[x][y]) cout<<"Yes"; else cout<<"No"; cout<<endl; } return 0; }