tsy1(欧拉函数+莫比乌斯函数)

题目链接

https://nanti.jisuanke.com/t/38226

题意

$n\le1e7$

题解

首先需要一个结论是 $\varphi(n^2)=n\varphi(n)$ ,这个可以通过素因子分解推出来,同理易得 $\varphi(n^3)=n^2\varphi(n)$

然后原式可以化为

然后设 $f(n)=\sum_{d|n}\varphi(d)\mu(\frac{n}{d})$ ,有

然后用积性函数预处理 $f(n)$ 和 $n^3f(n)$ ,然后分块就行了。。




代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
*         ┏┓    ┏┓
*         ┏┛┗━━━━━━━┛┗━━━┓
*         ┃       ┃  
*         ┃   ━    ┃
*         ┃ >   < ┃
*         ┃       ┃
*         ┃... ⌒ ...  ┃
*         ┃ ┃
*         ┗━┓ ┏━┛
*          ┃ ┃ Code is far away from bug with the animal protecting          
*          ┃ ┃ 神兽保佑,代码无bug
*          ┃ ┃           
*          ┃ ┃       
*          ┃ ┃
*          ┃ ┃           
*          ┃ ┗━━━┓
*          ┃ ┣┓
*          ┃ ┏┛
*          ┗┓┓┏━━━━━━━━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#include<complex>
#include<assert.h>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y)/2
#define NM 10000005
#define nm 105
using namespace std;
const double pi=acos(-1);
const ll inf=1073741824;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}



ll f[NM],ans;
int n,prime[NM],tot;
bool v[NM];


void init(){
n=1e7;f[1]=1;
inc(i,2,n){
if(!v[i])prime[++tot]=i,f[i]=i-2;
inc(j,1,tot){
if(i*prime[j]>n)break;
v[i*prime[j]]++;
if(i%prime[j]==0){
if(i/prime[j]%prime[j]==0)f[i*prime[j]]=f[i]*prime[j]%inf;
else f[i*prime[j]]=f[i/prime[j]]*(prime[j]-1)%inf*(prime[j]-1)%inf;
break;
}
f[i*prime[j]]=f[i]*f[prime[j]]%inf;
}
}
inc(i,1,n)f[i]=f[i]*i%inf*i%inf*i%inf;
inc(i,1,n)f[i]+=f[i-1],f[i]%=inf;
}

ll fun(ll t){
ll x=t+1,y=2*t+1;
if(t%2==0)t/=2;
else x/=2;
if(t%3==0)t/=3;
else if(x%3==0)x/=3;
else y/=3;
return t*x%inf*y%inf;
}

int main(){
init();
int _=read();while(_--){
n=read();
ans=0;
for(int i=1,j;i<=n;i=j+1){
j=n/(n/i);ll t=n/i;
t=t*(t+1)/2%inf*t%inf*fun(t)%inf;
ans+=t*(f[j]-f[i-1]+inf)%inf;
ans%=inf;
}
printf("%lld\n",ans);
}
}