http://poj.org/problem?id=3090

题目大意:你站在(0,0)的点上看向第一向限的点,点和点会互相阻挡,问最多看到多少点。

很容易想到,我们能看到的点,它的横纵坐标一定是互质的,那么怎么求呢?

首先我们要知道一个东西叫做法雷级数:

F1:0/1 1/1
F2:0/1 1/2 1/1
F3:0/1 1/3 1/2 2/3 1/1
F4:0/1 1/4 1/3 1/2 2/3 3/4 1/1
F5:0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1
F6:0/1 1/6 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 5/6 1/1
……
我们发现新加进来的数,它的分母为n,分子与n互质,所以加入了与n互质的数的个数。
是不是欧拉函数啊(叫做E)
所以Fn=Fn-1+En
但是我们知道我们要求的F可以分子分母相反,那么实际我们求的是Fn*2-1(-1因为1/1)
#include<cstdio>
#include<cctype>
#include<iostream>
using namespace std;
inline int read(){
int X=,w=; char ch=;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
int f[],e[];
bool h[];
int p[],cnt=;
void Euler(int n){
e[]=;
for(int i=;i<=n;i++){
if(!h[i]){
cnt++;
p[cnt]=i;
e[i]=i-;
}
for(int j=;j<=cnt&&i*p[j]<=n;j++){
h[i*p[j]]=;
if(i%p[j]==){
e[i*p[j]]=e[i]*p[j];
break;
}
e[i*p[j]]=e[i]*(p[j]-);
}
}
return;
}
void Farley(int n){
f[]=;
for(int i=;i<=n;i++){
f[i]=f[i-]+e[i];
}
return;
}
int main(){
Euler();
Farley();
int c=read();
for(int i=;i<=c;i++){
int n=read();
printf("%d %d %d\n",i,n,f[n]*-);
}
return ;
}

POJ3090:Visible Lattice Points——题解的更多相关文章

  1. POJ3090 Visible Lattice Points

    /* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...

  2. ACM学习历程—POJ3090 Visible Lattice Points(容斥原理 || 莫比乌斯)

    Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal ...

  3. POJ3090 Visible Lattice Points 欧拉函数

    欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...

  4. POJ3090 Visible Lattice Points (数论:欧拉函数模板)

    题目链接:传送门 思路: 所有gcd(x, y) = 1的数对都满足题意,然后还有(1, 0) 和 (0, 1). #include <iostream> #include <cst ...

  5. [POJ3090]Visible Lattice Points(欧拉函数)

    答案为3+2*∑φ(i),(i=2 to n) Code #include <cstdio> int T,n,A[1010]; void Init(){ for(int i=2;i< ...

  6. POJ3090 Visible Lattice Points 欧拉筛

    题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...

  7. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

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

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

  9. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

随机推荐

  1. 汽车后市场:数据入口在哪里?不看你就OUT啦!

    当前中国汽车后服务市场基本可分七个大类:包括养护.维修.改装.二手车.汽车配件.相关电商及金融保险等,汽车后市场整个产业链对数据服务都有刚性需求. 数据能为行业服务提高效率,提升商家对于客户以及业务的 ...

  2. 【转】VSstudio中的一些宏

    说明 $(RemoteMachine) 设置为“调试”属性页上“远程计算机”属性的值.有关更多信息,请参见更改用于 C/C++ 调试配置的项目设置. $(References) 以分号分隔的引用列表被 ...

  3. Java进阶知识点:不要只会写synchronized - JDK十大并发编程组件总结

    一.背景 提到Java中的并发编程,首先想到的便是使用synchronized代码块,保证代码块在并发环境下有序执行,从而避免冲突.如果涉及多线程间通信,可以再在synchronized代码块中使用w ...

  4. C++clock()延时循环

    函数clock(),返回程序开始执行后所用的系统时间,但是有两个复制问题. 1.clock()返回时间的单位不一定是秒 2.该函数的返回类型在某些系统上可能是Long,也可能是unsigned lon ...

  5. [2018 ACL Long] 对话系统

    [NLG - E2E - knowledge guide generation] 1. Knowledge Diffusion for Neural Dialogue Generation ( ‎Ci ...

  6. LeetCode - 231. Power of Two - 判断一个数是否2的n次幂 - 位运算应用实例 - ( C++ )

    1.题目:原题链接 Given an integer, write a function to determine if it is a power of two. 给定一个整数,判断该整数是否是2的 ...

  7. 编译安装hadoop2.6.3

    一.安装环境 1.1  JAVA  安装java1.7 下载jdk1.7: [root@node1~]# wget http://download.oracle.com/otn-pub/java/jd ...

  8. POJ 2455 Secret Milking Machine(最大流+二分)

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  9. 业务迁移---web

    #本文是做记录使用,不做为任何参考文档# 迁移代码 将源代码scp至新的server上 搭建服务 yum安装nginx服务 yum install nginx #yum安装 service nginx ...

  10. Java 集合框架之Collection

    此图是 java 中 Collection 相关的接口与类的关系的类图.其中,类只是集合框架的一部分,比较常用的一部分. 第一次画类图,着实很费劲,不过收获也不小. 下面是相关接口和类的解释说明.文字 ...