神犇和蒟蒻

( ext{Description})

传送门

( ext{Solution})

显然 (A) 的值就是 (1)

第二个其实就是 (varphi(i^2)) 的转化(显然 (i,i^2) 包含的质数相同):

[varphi(i^2)=i^2 imes prod_{i=1}^k(1-frac{1}{p_i}) ]

[varphi(i)=i imes prod_{i=1}^k(1-frac{1}{p_i}) ]

所以 (varphi(i^2)=varphi(i) imes i)

然后用 ( ext{id}) 来配凑再杜教筛就行了。

好不走心。

( ext{Code})

#include <cstdio>

#define rep(i,_l,_r) for(register signed i=(_l),_end=(_r);i<=_end;++i)
#define fep(i,_l,_r) for(register signed i=(_l),_end=(_r);i>=_end;--i)
#define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
#define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
#define print(x,y) write(x),putchar(y)

template <class T> inline T read(const T sample) {
    T x=0; int f=1; char s;
    while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
    while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
    return x*f;
}
template <class T> inline void write(const T x) {
    if(x<0) return (void) (putchar('-'),write(-x));
    if(x>9) write(x/10);
    putchar(x%10^48);
}
template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
template <class T> inline T fab(const T x) {return x>0?x:-x;}
template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;}
template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;}
template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}

#include <map>
using namespace std;
typedef long long ll;

const int maxn=5e6,mod=1e9+7;

int n,p[maxn>>1],pc,phi[maxn+5],inv6;
bool is[maxn+5];
map <int,int> mp;

int qkpow(int x,int y) {
	int r=1;
	while(y) {
		if(y&1) r=1ll*r*x%mod;
		x=1ll*x*x%mod; y>>=1;
	}
	return r;
}

void init() {
	phi[1]=1;
	rep(i,2,maxn) {
		if(!is[i]) p[++pc]=i,phi[i]=i-1;
		rep(j,1,pc) {
			if(i*p[j]>maxn) break;
			is[i*p[j]]=1;
			if(i%p[j]==0) {
				phi[i*p[j]]=phi[i]*p[j];
				break;
			}
			phi[i*p[j]]=phi[i]*(p[j]-1);
		}
	}
	rep(i,1,maxn) phi[i]=(phi[i-1]+1ll*i*phi[i]%mod)%mod;
}

int Goose(int n) {
	if(n<=maxn) return phi[n];
	if(mp.count(n)) return mp[n];
	int ret=1ll*n*(1ll+n)%mod*(2ll*n+1)%mod*inv6%mod,r;
	for(int l=2;l<=n;l=r+1) {
		r=(n/(n/l));
		ret=(0ll+ret-1ll*(l+r)*(r-l+1)/2%mod*Goose(n/l)%mod+mod)%mod;
	}
	mp.insert(make_pair(n,ret));
	return ret;
}

int main() {
	init(); inv6=qkpow(6,mod-2);
	n=read(9),puts("1");
	print(Goose(n),'
');
	return 0;
}
原文地址:https://www.cnblogs.com/AWhiteWall/p/14360765.html