由图可知,一个人无法被看到时,当且仅当有 人与原点 的斜率与他相同,且在他之前。

∴一个人可以被看到,设其斜率为y/x,当且仅当y/x不可再约分,即gcd(x,y)=1。

考虑将图按对角线划分开,两部分对称,

对其中的下半部分来说,枚举x,其所对应的y值(y<x)有几个与它互质的,则其对答案的贡献就是几。

这个值显然就是phi(x),所以枚举phi(x),将它们加起来即可。

 #include<cstdio>
using namespace std;
int n,phi[];
//bool get_phi(const int &x)//求单个数的phi
//{
// int ans=n;
// for(int i=2;i*i<=x;i++)
// if(n%i==0)
// {
// ans=ans/i*(i-1);
// while(n%i==0) n%=i;
// }
// if(n>1) ans=ans/n*(n-1);
//}
void phi_table()
{
phi[]=;//规定phi(1)=1;
for(int i=;i<=n;i++)
if(!phi[i])//若i是质数(类似筛法的思想)
for(int j=i;j<=n;j+=i)//i一定是j的质因数
{
if(!phi[j]) phi[j]=j;
phi[j]=phi[j]/i*(i-);
}
}
int main()
{
scanf("%d",&n);
if(n==) printf("3\n");
else if(n==) puts("");
else
{
long long ans=;
phi_table();
for(int i=;i<n;i++) ans+=(long long)phi[i];
printf("%lld\n",ans<<|);
}
return ;
}

【数论】【欧拉函数】bzoj2190 [SDOI2008]仪仗队的更多相关文章

  1. 【数论·欧拉函数】SDOI2008仪仗队

    题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如右图 ...

  2. 数论-欧拉函数-LightOJ - 1370

    我是知道φ(n)=n-1,n为质数  的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...

  3. 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)

    题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...

  4. 【bzoj2190】: [SDOI2008]仪仗队 数论-欧拉函数

    [bzoj2190]: [SDOI2008]仪仗队 在第i行当且仅当gcd(i,j)=1 可以被看到 欧拉函数求和 没了 /* http://www.cnblogs.com/karl07/ */ #i ...

  5. 【bzoj2190】[SDOI2008]仪仗队 数论 欧拉函数 筛法

    http://www.lydsy.com/JudgeOnline/problem.php?id=2190   裸欧拉函数,先不计算对角线(a,a)的一列,然后算出1到n-1的所有欧拉函数相加*2,再加 ...

  6. BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)

    今天zky学长讲数论,上午水,舒爽的不行..后来下午直接while(true){懵逼:}死循全程懵逼....(可怕)Thinking Bear. 2190: [SDOI2008]仪仗队 Time Li ...

  7. Codeforces_776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...

  8. Codeforces 776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...

  9. 数论 - 欧拉函数模板题 --- poj 2407 : Relatives

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Descri ...

  10. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

随机推荐

  1. HDU2255:奔小康赚大钱(KM算法)

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  2. 封装安卓的okhttp

    1.封装了get方法,handler更新主线程,回调的onsuccess,onfailure,onerror等方法 2.配置文件 api 'com.android.support:recyclervi ...

  3. 安卓topbar编码实战

    1.先在res->value下新建attrs.xml文件 <?xml version="1.0" encoding="utf-8"?> < ...

  4. jquery处理鼠标左中右键事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. ()()()()x()=()()()()填1-9数字

    /** Function: ()()()()x()=()()()() Developer: Date: */ #include "iostream" #include " ...

  6. 【SPOJ-QTREE】树链剖分

    树链剖分学习 https://blog.csdn.net/u013368721/article/details/39734871 https://www.cnblogs.com/George1994/ ...

  7. HDU5772 String problem

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission ...

  8. LeetCode 5:Given an input string, reverse the string word by word.

    problem: Given an input string, reverse the string word by word. For example: Given s = "the sk ...

  9. [Leetcode Week4]H-Index

    H-Index题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/h-index/description/ Description Given an arr ...

  10. Shell Script Basics

    https://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/ShellScripting/shell_scr ...