BZOJ2190 仪仗队

BZOJ2190仪仗队

题目传送门

题解

被机房大佬钦点sibo的一道题目,虽然好像真的并不是特别难。观察一下发现只有横纵坐标(gcd)为1的点才能被看到,而且这个图是对称的,所以相当于是求1到(n-1)的欧拉函数前缀和,然后乘以2加1,就是答案了。

code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('
');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
int n;
ll res;
/*==================Define Area================*/
int Euler(int x) {
	int res=x;
	for(int i=2;i*i<=x;i++) {
		if(x%i==0) {
			res=res-res/i;
			while(x%i==0) x/=i;
		}
	}
	if(x>1) res-=res/x;
	return res;
}

int main() {
	read(n);
	for(int i=1;i<n;i++) {
		res+=(ll)Euler(i);
	}
	printf("%lld
",res*2+1);
	return 0;
}

「我不敢下苦功琢磨自己,怕终于知道自己并非珠玉;然而心中既存着一丝希冀,便又不肯甘心与瓦砾为伍。」
原文地址:https://www.cnblogs.com/Apocrypha/p/9438599.html