【POJ3090】Visible Lattice Points
题目大意:求 $$\sum\limits_{i=2}^n\varphi(i)$$
题解:利用与埃筛类似的操作,可在 \(O(nlogn)\) 时间求出结果。
代码如下
#include <cstdio>
using namespace std;
const int maxn=3010;
int kase,n,phi[maxn];
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=2;i<=n;i++)phi[i]=i;
for(int i=2;i<=n;i++)if(i==phi[i])
for(int j=i;j<=n;j+=i)
phi[j]=phi[j]/i*(i-1);
long long ans=3;
for(int i=2;i<=n;i++)ans+=(phi[i]<<1);
printf("%d %d %lld\n",++kase,n,ans);
}
return 0;
}
【POJ3090】Visible Lattice Points的更多相关文章
- 【POJ 3090】 Visible Lattice Points
[题目链接] http://poj.org/problem?id=3090 [算法] 通过观察发现,在这个平面直角坐标系中,除了(1,1),(1,0)和(0,1),所有可见点的横纵坐标互质 那么,问题 ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- POJ3090:Visible Lattice Points——题解
http://poj.org/problem?id=3090 题目大意:你站在(0,0)的点上看向第一向限的点,点和点会互相阻挡,问最多看到多少点. 很容易想到,我们能看到的点,它的横纵坐标一定是互质 ...
- 【POJ】3090 Visible Lattice Points(欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7705 Accepted: ...
- Visible Lattice Points(规律题)【数学规律】
Visible Lattice Points 题目链接(点击) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9031 ...
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- poj 3060 Visible Lattice Points
http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Tota ...
随机推荐
- Mongodb主从复制/ 副本集/分片集群介绍
前面的文章介绍了Mongodb的安装使用,在 MongoDB 中,有两种数据冗余方式,一种 是 Master-Slave 模式(主从复制),一种是 Replica Sets 模式(副本集). Mong ...
- 软件工程M1/M2总结
也不分M1/M2了,就从头到尾的梳理一下这学期的软工课吧. 第一节课,老师就稀里哗啦说了一下这学期要怎么搞,什么个人项目啦,结对项目啦,团队项目一二啦,还要组队啊什么的,然后风风火火的组队. 个人项目 ...
- 【个人博客作业II】代码复审结果
[代码复审结果] General Does the code work? Does it perform its intended function, the logic is correct etc ...
- 2-Twenty Fifth Scrum Meeting-20151231
前言 因为服务器关闭,我们的开发项目也遭遇停滞一个星期.与网站开发负责人员协商之后,29号开放服务器.我们的项目也能够继续下去.比规定的开发时间(截止为2015/12/29)推迟. 事项安排 1.开发 ...
- Java源码--Array
1. Arrays.asList() 该方法是将数组转化为List,需要注意以下几点: (1)该方法不适用于基本数据类型(byte,short,int,long,float,double,boolea ...
- 第三个Sprint冲刺第五天(燃尽图)
- pandas的to_csv()使用细节和一些参数
dt.to_csv('C:/Users/think/Desktop/Result.csv',sep='?')#使用?分隔需要保存的数据,如果不写,默认是, dt.to_csv('C:/Users/th ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stu' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stu' defined ...
- shell之重定向
使用>和>>都表示向结果重定向到一个文件中,区别在于>是覆盖式的重定向,会先将内容先清空,然后再将结果输入,而>>是追加式的重定向,是将要输入的内容追加在在已存在的 ...
- PAT 1076 Wifi密码
https://pintia.cn/problem-sets/994805260223102976/problems/994805262622244864 下面是微博上流传的一张照片:“各位亲爱的同学 ...