-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.cpp
More file actions
46 lines (44 loc) · 1.09 KB
/
Copy patht.cpp
File metadata and controls
46 lines (44 loc) · 1.09 KB
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
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int mod=1000000007;
const int maxn=10000005;
bool check[maxn]; //用于打表记录的中间量
LL sumPhi[maxn]; //前i个的欧拉函数和
int cnt,phi[maxn],prime[maxn]; //素数个数,欧拉表,素数表
//素数表是第几个素数是什么,欧拉表是i的欧拉是phi[i];
void init(int n){ //素数+欧拉表
phi[1]=1;
cnt=0;
for(int i=2;i<=n;i++){
if(!check[i]){
phi[i]=i-1;
prime[cnt++]=i;
}
for(int j=0;j<cnt;j++){
if(i*prime[j]>n)break;
check[i*prime[j]]=true;
if(i%prime[j]==0){
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else{
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
sumPhi[0]=0;
for(int i=1;i<=n;i++) sumPhi[i]=(sumPhi[i-1]+phi[i]);
}
int main(){
int n;
while(cin>>n){
LL ans=0;
init(n);
for(int i=0;i<cnt;i++){
ans+=sumPhi[n/prime[i]];
}
cout<<2*ans-cnt<<endl;
}
return 0;
}