就对了一个求调
查看原帖
就对了一个求调
1085953
llf2186706096楼主2024/11/20 16:42
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n;
map<int, int>a;
vector <int>f;
int prime[N];
int ans[N];
int z(int x) {
	int now = x;
	int sum = a[1];
	if (x == 1)return sum - 1;
	for (int i = 0; x != 1; i++) {
		int temp = 1;
		while (x % ans[i] == 0) {
			temp *= ans[i];
			if (temp == now) {
				sum += a[temp] - 1;
			} else {
				sum += a[temp];
			}

			x /= ans[i];
		}
	}
	return sum;
}
int main() {
	int cnt = 0;
	for (int i = 2; i <= N; i++) {
		if (!prime[i])ans[cnt++] = i;
		for (int j = 0; i * ans[j] <= N && j < cnt; j++) {
			prime[i * ans[j]] = 1;
			if (i % ans[j] == 0)break;
		}
	}
	 

	cin >> n;
	f = vector<int>(n + 5);
	for (int i = 0; i < n; i++) {
		scanf("%d", &f[i]);
		a[f[i]]++;
	}
	for (int i = 0; i < n; i++) {
		cout << z(f[i]) << endl;
	}






	return 0;
}
2024/11/20 16:42
加载中...