求调wa11

AT_abc191_f [ABC191F] GCD or MIN

elpsconr @ 2024-10-31 11:30:29

就是统计任意两个数的gcd然后小于最小的a[i]就加入集合感觉巨对,不知道为什么错了。求助

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul tuple<int,int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctz(x)
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=3e5+5,yyx=1e9+7;
vector<PII> to[N];
int n,m,a[N];
inline int mod(int x){
  return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
  return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
  return x<y?x=y,1:0;
}
inline void solve(){
  cin>>n;
  rep(i,1,n) cin>>a[i];
  set<int> s;
  sort(a+1,a+1+n);
  rep(i,1,n) rep(j,i+1,n){
    int d=__gcd(a[i],a[j]);
    if(d<a[1]) s.insert(d);
  }

  s.insert(a[1]);
  cout<<s.size()<<endl;
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  //freopen("D://321//in.txt","r",stdin);
  //freopen("D://321//out.txt","w",stdout);
  int _=1;
  //cin>>_;
  while(_--)
  solve();
  return 0;
}

|