This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n;
int a[N]; //a数组用来存输入的数据
int w[N]; //w[j]数组用来存j是多少个数字的倍数
int c[N]; //c[a[i]]数组用来存a[i]出现的次数,比如2出现了3次。
int Max; //输入的最大值是多少
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], c[a[i]]++, Max = max(Max, a[i]);//存入数据,并记录此数据出现的次数
//一个数一个数的枚举,将范围内的所有数字讨论一遍
for (int i = 1; i <= Max; i++)
for (int j = i; j <= Max; j += i) //枚举i的倍数,就是1*i,2*i,3*i,....
w[j] += c[i]; //记录数j是多少个数字的位数(累加,多个)
for (int i = 1; i <= n; i++)
printf("%d\n", w[a[i]] - 1);//要-1是因为奶牛不能拍自己(即a[i]不能被a[i]自己整除)
}