Diff-prime Pairs
我们可以发现任意两个的素数都符合题意
但是像
4
,
6
4,6
4,6 这样的合数也符合条件,它本质上就是
2
∗
2
,
2
∗
3
2*2,2*3
2∗2,2∗3,也就是
2
,
3
2,3
2,3 这对素数的拓展。
那么对于任意一对素数可以拓展多少对呢,我们可以发现他们的
g
c
d
gcd
gcd 是相同的,因此决定一对素数贡献的是其中较大的一个素数。
2
∗
x
<
=
n
,
3
∗
x
<
=
n
2*x<=n,3*x<=n
2∗x<=n,3∗x<=n
3
3
3 与比它小的素数
2
2
2 产生的贡献就是
n
3
(
因
子
含
有
3
的
数
的
个
数
\frac{n}{3}(因子含有3的数的个数
3n(因子含有3的数的个数
因此我们记录一下比素数
i
i
i 小的素数的个数,
i
i
i 与前
c
n
t
cnt
cnt 个素数产生的贡献就是
n
i
∗
c
n
t
\frac{n}{i} * cnt
in∗cnt
code:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e7 + 9;
int p[maxn], v[maxn], cnt;
ll n;
void init()
{
for(int i = 2; i <= maxn - 9; ++i)
{
if(!v[i]) p[++cnt] = i;
for(int j = 1; j <= cnt && 1ll * i * p[j] <= maxn - 9; ++j)
{
v[i * p[j]] = 1;
if(i % p[j] == 0){
break;
}
}
}
}
void work()
{
cin >> n;
ll ans = 0, cnt = 0;
for(int i = 2; i <= n; ++i) if(!v[i]){
ans += (n / i) * cnt;
++cnt;
}
cout << ans * 2 << endl;
}
int main()
{
ios::sync_with_stdio(0);
init();
work();
return 0;
}