bzoj2190 [SDOI2008]仪仗队

题目链接

如果只考虑y=x直线的上方

每一种斜率的直线只能打到一个人

转化为求一个数x(0~n-1)做分母时,有多少个数y与x互质(欧拉函数)

为什我我要做这种水题? 因为我太弱了

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<string>
 7 #include<cmath>
 8 #include<ctime>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<set>
13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
15 #define Clear(a,b) memset(a,b,sizeof(a))
16 #define inout(x) printf("%d",(x))
17 #define douin(x) scanf("%lf",&x)
18 #define strin(x) scanf("%s",(x))
19 #define LLin(x) scanf("%lld",&x)
20 #define op operator
21 #define CSC main
22 typedef unsigned long long ULL;
23 typedef const int cint;
24 typedef long long LL;
25 using namespace std;
26 void inin(int &ret)
27 {
28     ret=0;int f=0;char ch=getchar();
29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
31     ret=f?-ret:ret;
32 }
33 int n;
34 bool bo[1000010];
35 int p[100010],x,phi[100010];
36 void getphi()
37 {
38     phi[1]=1;
39     re(i,2,n)
40     {
41         if(!bo[i])p[++x]=i,phi[i]=i-1;
42         for(int j=1;j<=x&&i*p[j]<=n;j++)
43         {
44             bo[i*p[j]]=1;
45             if(i%p[j]==0)
46             {
47                 phi[i*p[j]]=phi[i]*p[j];
48                 break;
49             }
50             else phi[i*p[j]]=phi[i]*(p[j]-1);
51         }
52     }
53 }
54 int main()
55 {
56     inin(n);
57     getphi();int ans=0;
58     re(i,1,n-1)ans+=phi[i];
59     cout<<(ans*2+1);
60      return 0;
61 }
原文地址:https://www.cnblogs.com/HugeGun/p/5248752.html