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)这个点
 /*************
bzoj 2190
by chty
2016.11.3
*************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 40010
int n,ans,phi[MAXN],check[MAXN],prime[MAXN];
inline int read()
{
int x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
void get()
{
phi[]=; int cnt=;
for(int i=;i<=n;i++)
{
if(!check[i]) {prime[++cnt]=i; phi[i]=i-;}
for(int j=;j<=cnt&&prime[j]*i<=n;j++)
{
check[prime[j]*i]=;
if(i%prime[j]) phi[i*prime[j]]=phi[i]*(prime[j]-);
else {phi[i*prime[j]]=phi[i]*prime[j]; break;}
}
}
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
n=read(); get();
for(int i=;i<n;i++) ans+=phi[i];
printf("%d\n",ans*+);
return ;
}
 
 
 

最新文章

  1. [转]在Eclipse中使用JUnit4进行单元测试(中级篇)
  2. 【CQgame】[幸运方块 v1.1.2] [Lucky_Block v1.1.2]
  3. 第一次IT技术面试经历
  4. logstash redis kafka传输 haproxy日志
  5. ECMAScript6 面向对象 时钟效果
  6. 使用Python获取Linux系统的各种信息
  7. 基于RDBMS的BI设计
  8. 如何查找Mac上的USB存储设备使用痕迹
  9. IOS开发之后台处理
  10. Apache的编译安装error: APR not found. Please read the documentation
  11. Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
  12. OPenGL中三维图形的矩阵变换
  13. ###学习《C++ Primer》- 5
  14. ExtJS4加载FormPanel数据的几种方式
  15. 如何在Blog中使用feedburner管理RSS订阅
  16. Python3使用Print输出带颜色字体
  17. 【转载】使用SDL播放YUV图像数据(转)
  18. Anaroid WebView API详解
  19. Keras官方中文文档:常见问题与解答
  20. springdata 多对多配置

热门文章

  1. AS3舞台的大小,可视区域大小及SWF文件的原始尺寸大小
  2. LINUX下的ssh登录之后的文件远程copy:scp命令(接前文ssh登录)
  3. [STM32]HardFault 定位办法
  4. mysql-jdbc创建Statement与执行SQL
  5. 21天学通C++_Day3_Part3
  6. IDEA导出想要的sql供H2数据库使用
  7. 分布式缓冲之memcache
  8. CDlinux无线破解系统
  9. The type javax.xml.rpc.ServiceException cannot be resolved.It is indirectly
  10. Vue.js:模版语法