月月给华华出题 https:ac.nowcoder.comacmproblem23048

月月给华华出题 https:ac.nowcoder.comacmproblem23048,第1张

月月给华华出题 https://ac.nowcoder.com/acm/problem/23048

 

#include
using namespace std;
const int N=1e6+3;
#define ll long long 
ll phi[N],f[N];int n;
void getphi()
{
	for(int i=1;i<=N;i++) phi[i]=i;
	for(int i=2;i<=N;i++)
	{
		if(phi[i]==i)
		{
			phi[i]=i;
			for(int j=i;j<=N;j+=i)
			{
			phi[j]=phi[j]*(i-1)/i;
			}
		}
	}
	return ;
}
void getans()
{
	for(int i=1;i<=n;i++)
	{
	  f[i]+=1;//1是任何数的约数,但是phi[1]*1/2=0;故需要+1
	  for(int j=i+i;j<=n;j+=i)
	  {
	  	f[j]+=phi[j/i]*(ll)(j/i)/2;
	  }
	}
	return ;
}
int main()
{
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
 	getphi();getans();
 	for(int i=1;i<=n;i++)
 	{
 		cout< 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5703023.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存