Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
115683 陈家宝 互质组 C++ 运行超时 0 1000 MS 244 KB 1666 2023-12-12 17:07:31

Tests(0/5):


#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline long long fr(){ register long long x=0,f=1; static char c=getchar(); while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=x<<1+x<<3+c^48; c=getchar(); } return x*f; } inline void fw(long long x){ if(x==0){ putchar('0'); return; } if(x<0){ x=-x; putchar('-'); } stack<char> s; while(x){ s.push((x%10)+'0'); x/=10; } while(!s.empty()){ putchar(s.top()); s.pop(); } } inline void CCF(int opt){ ios::sync_with_stdio(false); if(opt==0){ cout.tie(0); return; } if(opt>=1) cin.tie(0); if(opt>=2) cout.tie(0); } inline void DEBUG(){ puts("IAKIOI"); } } using namespace Fast; int a[15],cnt,n; bool f[15][15],c[15]; bool check(int x){ int cnt=0; memset(c,false,sizeof(c)); for(int i=1;i<=n;i++){ if(c[i]) continue; cnt++; vector<int> vec; vec.clear(); vec.push_back(i); c[i]=true; for(int j=1;j<=n;j++){ if(c[j]) continue; if(!f[i][j]){ bool fl=true; for(int k=0;k<vec.size();k++){ if(f[vec[k]][j]){ fl=false; break; } } if(fl){ vec.push_back(j); c[j]=true; } } } } return cnt<=x; } signed main(){ n=fr(); for(int i=1;i<=n;i++) a[i]=fr(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(__gcd(a[i],a[j])!=1) f[i][j]=true; } } int l=0,r=n; while(l<=r){ int mid=(l+r)/2; if(check(mid)) r=mid-1; else l=mid+1; } fw(l); return 0; }


测评信息: