zoukankan      html  css  js  c++  java
  • 【bzoj2190】[SDOI2008]仪仗队

    2190: [SDOI2008]仪仗队

    Time Limit: 10 Sec  Memory Limit: 259 MB
    Submit: 2638  Solved: 1674
    [Submit][Status][Discuss]

    Description

      作为体育委员,C君负责这次运动会仪仗队的训练。仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图)。       现在,C君希望你告诉他队伍整齐时能看到的学生人数。

    Input

      共一个数N。

    Output

      共一个数,即C君应看到的学生人数。

    Sample Input

      4

    Sample Output

      9
     
     
     
    【题解】
    显然,能看见的点坐标应满足gcd(x,y)=1
    用欧拉函数解之即可。最后别忘了加上(0,0)这个点
     1 /*************
     2   bzoj 2190
     3   by chty
     4   2016.11.3
     5 *************/
     6 #include<iostream>
     7 #include<cstdio>
     8 #include<cstring>
     9 #include<cstdlib>
    10 #include<ctime>
    11 #include<cmath>
    12 #include<algorithm>
    13 using namespace std;
    14 #define MAXN 40010
    15 int n,ans,phi[MAXN],check[MAXN],prime[MAXN];
    16 inline int read()
    17 {
    18     int x=0,f=1;  char ch=getchar();
    19     while(!isdigit(ch))  {if(ch=='-')  f=-1;  ch=getchar();}
    20     while(isdigit(ch))  {x=x*10+ch-'0';  ch=getchar();}
    21     return x*f;
    22 }
    23 void get()
    24 {
    25     phi[1]=1;  int cnt=0;
    26     for(int i=2;i<=n;i++)
    27     {
    28         if(!check[i])  {prime[++cnt]=i; phi[i]=i-1;}
    29         for(int j=1;j<=cnt&&prime[j]*i<=n;j++)
    30         {
    31             check[prime[j]*i]=1;
    32             if(i%prime[j])  phi[i*prime[j]]=phi[i]*(prime[j]-1);
    33             else {phi[i*prime[j]]=phi[i]*prime[j];  break;}
    34         }
    35     }
    36 }
    37 int main()
    38 {
    39     freopen("cin.in","r",stdin);
    40     freopen("cout.out","w",stdout);
    41     n=read();  get();
    42     for(int i=1;i<n;i++)  ans+=phi[i];
    43     printf("%d
    ",ans*2+1);
    44     return 0;
    45 }
     
     
     
  • 相关阅读:
    [转载]辗转相除法
    [转载]自由不是什么
    [翻译]与比尔·盖茨面对面
    [翻译]AJAX XMLHttpRequest对象 详解
    [转载]Win32应用程序中进程间通信方法分析与比较
    C# 中的类型转换
    Log4Net
    抽象类和接口
    有用的自定义pagecounter控件
    单点登陆单web应用的单点登陆
  • 原文地址:https://www.cnblogs.com/chty/p/6026460.html
Copyright © 2011-2022 走看看