跳到正文

个人记录

2025.11.15

swordofsky约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年11月15日
收录
2026年2月22日
更新
2026年11月13日
篇幅
约 1 分钟

版本

  1. v1当前

A - Not Adding(0pts)

CF

考虑每一个数最终能不能在数组中

如果这个数能在原数组中能用若干个数的gcd表示,那么这个数最终就能在数组中,而且这若干个数必须是这个数的倍数

所以对于每个数,枚举倍数,将在原数组中的数取gcd,等于这个数就cnt++

C++
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a[1000005],s[1000005],mp[1000005],cnt;
vector<ll>q;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		s[a[i]]=1;
	}
	for(int i=1;i<=1000000;i++){
		ll g=0;
		for(ll j=i;j<=1000000;j+=i){
			if(s[j]) g=__gcd(g,j);
			if(i==g) break;
		}
		if(i==g) cnt++;
	}
	cout<<cnt-n;
	return 0;
}
原文