因为图像关于对角线对称.所以我们仅仅看下三角区域. 将x轴看做分母,被圈的点看成分子 依次是{1/2},{1/3,1/2},{1/4,3/4},{1/5,2/5,3/5,4/5} 写成前缀和的形式就是 {1/2},{1/2,1/3,2/3},{1/2,1/3,2/3,1/4,3/4},{1/2,1/3,2/3,1/4,3/4,1/5,2/5,3/5,4/5} 发现.这就是一个法雷级数,即第k项添加的数就是phi[k]. 最后的答案*2+(0,1)+(1,0),(1,1)三个点就好了 #inclu…
Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: 3317 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible fr…
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见,x与y仅仅有互质的情况下才会发生(0,0)与(x,y)交点不经过其它的点的情况,对于x,y等于N时,能够选择的点均为小于等于N而且与N互质的数,共Euler(N)个,而且不重叠.所以能够得到递推公式aa[i]=aa[i]+2*Euler(N). 代码: #include <iostream> #i…
http://poj.org/problem?id=3090 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1777 题目大意: 给你一个坐标系和一个范围,求x.y在[0,N]这个范围内,未被挡住点的个数. 被挡住的点定义为:从原点引一条射线到某个点,若之前经过其他的点,则被挡住. 思路: 未被挡住的一定是互质的(由斜率可以想到) 然后直接打表吧. #include<cstdio> const int MAXN=1002;…
这是好久之前做过的题,算是在考察欧拉函数的定义吧. 先把欧拉函数讲好:其实欧拉函数还是有很多解读的.emmm,最基础同时最重要的算是,¢(n)表示范围(1, n-1)中与n互质的数的个数 好了,我把规律都放在图上了. 代码就自己写吧.…
<题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多大,(0,1),(1,1),(1,0)这三个点一定能够看到,除这三个点以外,我们根据图像分析可得,设一个点的坐标为(x,y) ,那么只有符合gcd(x,y)=1的点才能被看到.又因为 (0,0)---(n,n)对角线两端的点对称,所以我们只需算一边即可,而一边的点数根据欧拉函数可得: $\sum_{i=2}^…
原题 欧拉函数 我们发现,对于每一个斜率来说,这条直线上的点,只有gcd(x,y)=1时可行,所以求欧拉函数的前缀和.2*f[n]+1即为答案. #include<cstdio> #define N 1010 using namespace std; int x,y,n,f[N],m; int read() { int ans=0,fu=1; char j=getchar(); for (;(j<'0' || j>'9') && j!='-';j=getchar()…
题目: 给一个n,n的网格,点可以遮挡视线,问从0,0看能看到多少点 题解: 根据对称性,我们可以把网格按y=x为对称轴划分成两半,求一半的就可以了,可以想到的是应该每种斜率只能看到一个点 因为斜率表达式k=y/x,所以直线上的点都满足这个关系,那么显然当gcd(x,y)==1的时候这个点是直线上的第一个点,其他点的坐标一定是这个点的若干倍 所以问题转化成求gcd(x,y)==1的点对个数,即∑phi[i](1<=i<=n) 欧拉函数即可 #include<cstdio> usin…
http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6153   Accepted: 3662 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other…
Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7705   Accepted: 4707 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible fr…
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c有公因子1<b<min(r,c),则(c/b, r/b)在线段(0, 0)(c, r)上,则(c, r)不是可见格点.(充分性) 若r与c互质,显然线段上不存在整点,则(c, r)不是可见格点.(必要性) φ(n)表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值 也就是横坐标增1后纵坐标合…
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible…
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time Limit: 1368MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submit Status Description Consider a N*N*N lattice. One corner is at (0,0,0) and…
P8 Visible Lattice Points Time Limit:1000ms,     Memory Limit:65536KB Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0…
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; //欧拉函数模板 int Euler(int n) { int num = n; for(int i = 2;i <= n;i++) { if(n % i == 0) { num = num / i * (i-1); } while(n % i == 0) { n /= i; } } return num…
Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点(2,4,6)可以等价成(1,2,3)即经过(1,2,3)的线一定经过(2,4,6): 莫比乌斯反演的模板题, 由于点坐标可以为0 , 需要考虑 x, y, z 中两个为0 和一个为0 的情况 : 两个为0 时 : 有 三个点(在x , y, z 轴上): 一个为0 时 : mu[i] * (n/i…
VLATTICE - Visible Lattice Points no tags  Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lattice poin…
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lat…
/** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0,0,0)另一侧为(n,n,n): 问从(0,0,0)出发的经过该范围三维空间内整数点坐标的射线有多少条. 思路: 类比二维的:求1<=x<=n,1<=y<=n; gcd(x,y)=1的对数.因为y/x,所以可以反过来. 三维的:求1<=x,y,z<=n; gcd(x,y,…
Visible Lattice Points Time Limit:7000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from co…
Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lattice point lies on the segmen…
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lat…
Visible Lattice Points 题目链接(点击) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9031   Accepted: 5490 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is v…
A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the point…
[题目链接] http://poj.org/problem?id=3090 [算法] 通过观察发现,在这个平面直角坐标系中,除了(1,1),(1,0)和(0,1),所有可见点的横纵坐标互质 那么,问题就转化为了求 2 * (phi(1) + phi(2) + ... + phi(n)) + 3 预处理phi的前缀和,O(1)回答询问,即可 [代码] #include <algorithm> #include <bitset> #include <cctype> #inc…
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 2478]Farey Sequence(数论--欧拉函数 找规律求前缀和) 求 x/y,gcd(x,y)=1 且 x<y 很像.   而由于这里 x可等于或大于y,于是就求 欧拉函数的前缀和*2+边缘2个点+对角线1个点. 1 #include<cstdio> 2 #include<cst…
题意: UVa 10820 这两个题是同一道题目,只是公式有点区别. 给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 对于点(x, y), 若g = gcd(x, y) > 1,则该点必被点(x/g, y/g)所挡住. 因此所见点除了(1, 0)和(0, 1)满足横纵坐标互素. 最终答案为,其中的+3对应(1, 1) (1, 0) (0, 1)三个点 #include <cstdio> ; ]; void get_table() { ; i <= m…
一.题目 A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the p…
Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example…
欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass throu…