【题目分析】

    狄利克雷卷积。

    BZOJ 2705 [SDOI2012]Longge的问题 ——Dirichlet积

    然后直接求出欧拉函数,计算和即可。

【代码】

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>

#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

#define maxn 500005
#define ll long long
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)

void Finout()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    #endif
}

int Getint()
{
    int x=0,f=1; char ch=getchar();
    while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int n;

int phi(int x)
{
//	cout<<"phi"<<x;
	int ret=x;
	F(i,2,sqrt(x))
	{
		if (x%i==0) ret/=i,ret*=(i-1);
		while (x%i==0) x/=i;
	}
	if (x>1) ret=ret/x*(x-1);
//	cout<<" is "<<ret<<endl;
	return ret;
}

ll ans=0;

int main()
{
    Finout();
    n=Getint();
    F(i,1,sqrt(n)) if (n%i==0)
    {
    	ans+=(ll)phi(i)*(n/i);
    	if (i*i<n) ans+=(ll)phi(n/i)*i;
	}
    cout<<ans<<endl;
}

  

 

相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2021-12-23
  • 2021-12-08
  • 2021-12-03
  • 2021-10-11
  • 2021-12-20
  • 2022-01-11
猜你喜欢
  • 2022-01-25
  • 2021-10-10
  • 2021-09-04
  • 2021-08-06
  • 2021-12-02
  • 2021-09-22
相关资源
相似解决方案