-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.cpp
More file actions
46 lines (43 loc) · 728 Bytes
/
Copy pathF.cpp
File metadata and controls
46 lines (43 loc) · 728 Bytes
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;
const int maxn = 100005;
typedef long long ll;
int n,m;
bool p[maxn];
int prime[maxn],top;
int mu[maxn];
ll phi[maxn];
void init(){
memset(p,0,sizeof p);
top=0;
phi[1]=1;
for(int i=2;i<maxn;i++){
if(!p[i]){
prime[++top]=i;
phi[i]=i-1;
}
for(int j=1;j<=top;j++){
if(i*prime[j]>=maxn) break;
p[i*prime[j]]=1;
if(i % prime[j] == 0){
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
phi[i*prime[j]]=phi[i]*phi[prime[j]];
}
}
}
int main(){
int T;
init();
for(;~scanf("%d%d",&n,&m);){
if(n>m) swap(n,m);
ll res = 0;
for(int i=1;i<=n;i++)
res += (ll)phi[i]*(n/i)*(m/i);
res += res;
res -= (ll)n*m;
cout<<res<<endl;
}
return 0;
}