for (int i = 2; i <= n; ++i)//埃氏筛法,建边
if (!b[i])
{
for (int j = i * 2; j <= n; j += i)
b[j] = 1;
for (int j = 1; j * i <= n; j++)
{
d[j * i]++;
v[j].push_back(j * i);
}
}
拓扑排序
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i = 0; i < v[u].size(); i++)
{
d[v[u][i]]--;
ans[v[u][i]] += ans[u];//累加答案
if (!d[v[u][i]])
q.push(v[u][i]);
}
}