0
点赞
收藏
分享

微信扫一扫

D. Not Adding

兽怪海北 2022-01-16 阅读 44
https://codeforces.com/contest/1627/problem/D
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
typedef long long ll;
typedef pair<char, int > PII;

int n;

int _gcd (int a, int b) {
	return b?_gcd(b, a %b) : a;
}
void solve() {
	cin >> n;
	vector<int> a(n );
	map<int, int> st;
	for (int i =1; i<= n;i ++) {
	    int t;
	    cin >> t;
	    a[t] =1;
	}
	int maxv = *max_element(a.begin(), a.end());
	 
	 int cnt = 0;
	 int g[N] = {0};
	for (int i =1 ; i <= N - 10; i ++) {
		for (int j = i; j <= N - 10; j += i)
			if (a[j])
				g[i] = _gcd(g[i], j);
		if (g[i] == i && !a[i]) cnt ++;
	}
	cout << cnt << endl;
}
int main () {
	int t;
    t = 1;
	
	while (t --) solve();
	return 0;
} 

如果gcd(a1, a2, a3..) = x 即g[x] = x那么就可以构造出这样一个答案否则不可以。换一个查找方向

举报

相关推荐

0 条评论