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…
/** 题目: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…
这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 F[n]为所有满足三个数的最大公约数能被n整除的三元组数量 显然 F[n]=∑n|df[d] 然后由莫比乌斯反演,f[n]=∑n|dμ[d/n]*F[d] 情况三也是一样的 #include<iostream> #include<algorithm> #include<set&g…
http://www.spoj.com/problems/VLATTICE/ 明显,当gcd(x,y,z)=k,k!=1时,(x,y,z)被(x/k,y/k,z/k)遮挡,所以这道题要求的是gcd(x,y,z)==1的个数+{(x,y,0)|gcd(x,y)==1}的个数+3{(0,0,1),(0,1,0),(1,0,0)} 现在不去管最后的三个坐标轴上的点, 设f(i)=|{(x,y,0)|gcd(x,y)==i}|*3+|{(x,y,z)|gcd(x,y,z)==i}|,也就是不在坐标轴上且…
题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f(t)为gcd(x,y,z)==t或有一个0,另外的两个未知数gcd为t的组合数 定义F(x)为 ∑p(t)   x|t  =  (n/x)* (n/x) * (n/x+3) 那么满足下面的 则 求出f(1)即为答案 代码: #include<bits/stdc++.h> using namesp…
题目链接 /* http://www.spoj.com/problems/VLATTICE/ 题意:求一个n*n*n的晶体,有多少点可以在(0,0,0)处可以直接看到. 同BZOJ.2301 题目即要求gcd(i,j,k)=1的(i,j,k)数对个数,1<=i,j,k<=n 由于是立体,所以最后再算上平面的点和坐标轴上的三个点就行了 */ #include<cstdio> #include<cctype> #define gc() getchar() typedef l…
题目: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…
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…
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…
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…
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: 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 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…
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…
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…
/* * 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…
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…
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…
题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1    a,b,c <=N 的对数. 思路:我们令函数g(x)为gcd(a, b, c) = x的对数,那么这题就是要求g(1).我们令f(x)为x | gcd(a, b, c)的对数,显然f(n) = sigma(n | d, g(d)) .f(d) = (n/d) * (n/d) * (n/d),那么我们就可以用莫比乌斯反演公式了, g(n) = sigma(n |…
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^n[gcd(i,j,k)==1])+(\sum_{i=1}^n\sum_{j=1}^n[gcd(i,j)==1])\\+(\sum_{i=1}^n\sum_{k=1}^n[gcd(i,k)==1])+(\sum_{j=1}^n\sum_{k=1}^n[gcd(j,k)==1]) \]…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可以看到多少棵树.同一直线上的树只能看到最靠近人的那颗. 思路:可以将题目转化为求gcd(x, y) = 1,(1 <= x <= n, 1 <= y <= m)的对数.直接套用莫比乌斯反演即可. code: #include <cstdio> #include <cs…
题目链接 一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn=1e6; ]; ]; ]; void init() { mu[]=; ; ;i<=maxn;i++) { if(!check[i]) { prime[tot++]=i;…
#include<bits/stdc++.h> #define ll long long using namespace std; ; int vis[maxn]; int mu[maxn]; int prime[maxn]; ; int sum1[maxn]; int sum2[maxn]; void get_mu() { mu[]=; vis[]=; ;i<maxn;i++) { ; prime[++tot]=i; } ;j<=tot && i*prime[j]…
http://www.spoj.com/problems/VLATTICE/en/ 题意: 给一个长度为N的正方形,从(0,0,0)能看到多少个点. 思路:这道题其实和能量采集是差不多的,只不过从二维上升到了三维. 分三部分计算: ①坐标值上的点,只有3个. ②与原点相邻的三个表面上的点,需满足gcd(x,y)=1. ③其余空间中的点,需满足gcd(x,y,z)=1. #include<iostream> #include<algorithm> #include<cstrin…
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…
一.题目 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 throu…
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…
题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; ]; ],prime[],N=; ]; void get_phi() { int i, j, k; k = ; //有些题目1的欧拉函数是1,请注意 //phi[1]=1; ; i < N; i+…