Files
python/TangDou/LuoGuBook/P2926.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
951 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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]自己整除)
}