题目:
分析:
比赛时,个个
d
a
l
a
o
dalao
dalao都说是欧拉筛模版,但本蒟蒻早就忘了也,然后就死皮赖脸的写个暴力,骗到了
30
30
30分的高分
在洛谷上有道原题仪仗队,关于欧拉筛方面的,还是看看上面
d
a
l
a
o
dalao
dalao的操作吧
这里,就跟大家说下为什么可以用欧拉筛:
首先,一个点与
(
0
,
0
)
(0,0)
(0,0)没有中间点的时候,只有在
x
x
x与
y
y
y
互质:
为什么呢(表示很多题解都没写,感觉很不爽),我们将
x
,
y
x,y
x,y写成斜率的形式
→
y
−
0
x
−
0
→
y
x
→\frac{y-0}{x-0}→\frac{y}{x}
→x−0y−0→xy
而如果
g
c
d
(
x
,
y
)
≠
1
gcd(x,y)\neq 1
gcd(x,y)̸=1,也就说明了
y
x
\frac{y}{x}
xy不是最简分数,而将其化为最简分数,也就是
y
/
g
c
d
(
x
,
y
)
x
/
g
c
d
(
x
,
y
)
(
\frac{y/gcd(x,y)}{x/gcd(x,y)}(
x/gcd(x,y)y/gcd(x,y)(这个东东在很多博客都出现了
.
.
)
..)
..)
所以我们要求所有
g
c
d
gcd
gcd为
1
1
1的
x
,
y
x,y
x,y
然后我们将
(
1
,
1
)
(1,1)
(1,1)当做
(
0
,
0
)
(0,0)
(0,0),然后所有点往下和前移一步
我们可以发现点距离点
(
0
,
0
)
(0,0)
(0,0)只要有中点那么就不会被看到,那么我们就可以用欧拉函数来算互质。当然我们还要算上离
(
0
,
0
)
(0,0)
(0,0)最近的三个,所以答案就是:
3
+
∑
i
=
2
n
ϕ
(
i
)
3+\sum_{i=2}^n\phi(i)
3+i=2∑nϕ(i)
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
LL phi[100005];
int main()
{
LL n=read();
n--;
if(!n) return !printf("0");
for(LL i=2;i<=n;i++) phi[i]=i;
LL sum=0;
for(LL i=2;i<=n;i++)
{
if(phi[i]==i)
for(LL j=i;j<=n;j+=i)
phi[j]=phi[j]/i*(i-1);
sum+=phi[i];
}
cout<<3+2*sum;
return 0;
}