SSLOJ 1268.可见点数


题目:

传送门


分析:

比赛时,个个 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} x0y0xy
而如果 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=2nϕ(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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值