zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
    「我不敢下苦功琢磨自己,怕终于知道自己并非珠玉;然而心中既存着一丝希冀,便又不肯甘心与瓦砾为伍。」
  • 相关阅读:
    第二月 day 2,内置函数
    第二月 day3 闭包,递归
    day4 装饰器
    第二月 day1生成器
    第一个月 总结
    day 16 迭代器
    day 15 编码
    Docker常用命令
    DRF源码刨析
    django中使用qiniu作为第三方存储
  • 原文地址:https://www.cnblogs.com/Apocrypha/p/9438599.html
Copyright © 2011-2022 走看看