ID_7260 一道大水题

太水了…容易淹死人…

思路:

利用埃氏筛法建边,然后跑拓扑排序

细节:

注意是j除以i是质数(不是j或i

代码:

建边

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]);
	}
}
3 个赞

直接dp就行了孩子

1 个赞

\color{black}{黑色}
\color{darkgray}{深灰}
\color{gray}{灰色}
\color{silver}{银色}
\color{lightgray}{浅灰}
\color{white}{白色}
\color{brown}{棕色}
\color{maroon}{栗色}
\color{red}{红色}
\color{fuchsia}{桃红}
\color{magenta}{品红}
\color{pink}{粉红}
\color{orange}{橙色}
\color{yellow}{黄色}
\color{lime}{青柠}
\color{olive}{橄榄}
\color{green}{绿色}
\color{aqua}{水绿}
\color{cyan}{青色}
\color{skyblue}{天蓝}
\color{lightblue}{淡蓝}
\color{teal}{靛青}
\color{blue}{蓝色}
往下滑呀V
\color{navy}{海蓝}
\color{violet}{罗兰}
\color{lightgreen}{浅绿}
\color{lightyellow}{浅黄}
\color{darkred}{深红}
\color{darkorange}{深橘色}
\color{lightpink}{浅粉色}
\color{purple}{紫色}
6