CF691F Couple Cover
想暴力一点,我们可以直接将所有的 \(a_i\times a_j\) 都存到数组里,然后求个前缀和,可以直接枚举 \(a_i\) 这个值,然后再枚举 \(p\) 的最大值,即 \(10^6\) 然后找到另一个数 \(a_j=\frac{k}{a_i}\) 有多少个,时间复杂度和埃式筛一样。
\(\mathscr{Code:}\)
#include<bits/stdc++.h>
#define LL long long
//#define int LL
#define per(i, a, b) for (int i = a, END##i = b; i >= END##i; i--)
#define rep(i, a, b) for (int i = a, END##i = b; i <= END##i; i++)
#define repn(x) rep(x, 1, n)
#define repm(x) rep(x, 1, m)
#define pb push_back
#define e(x) for(int i = h[x], v = to[i]; i; i = nxt[i], v = to[i])
#define E(x) for(auto y : p[x])
#define PII pair<int, int>
#define i64 unsigned long long
#define YY puts("Yes"), exit(0)
#define NN puts("No"), exit(0)
using namespace std;
const int Mod = 1e9 + 7;
const int Inf = 0x3f3f3f3f;
const LL InfLL = 0x3f3f3f3f3f3f3f3f;
inline LL read() {LL s = 0, fu = 1; char ch = getchar(); while (ch < '0' || ch > '9') ch == '-' ? fu = -1 : 0, ch = getchar(); while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * fu;}
const int N = 3e6 + 10;
LL n, cnt[N], su[N];
inline void Main() {
n = read();
repn(i) cnt[read()]++;
rep(i, 1, N - 1) if (cnt[i])
for (int j = i; j < N; j += i)
su[j] += cnt[i] * (cnt[j / i] - (j / i == i));
rep(i, 1, N - 1) su[i] += su[i - 1];
int m = read();
while (m--) {
int p = read();
printf("%lld\n", n * (n - 1) - su[p - 1]);
}
}
signed main() {
// freopen("input.in", "r", stdin);
int T = 1;
while (T--)
Main();
return 0;
}

浙公网安备 33010602011771号