[SPOJ7001]VLATTICE - Visible Lattice Points】的更多相关文章

题目大意: $q(q\leq50)$组询问,对于给定的$n(n\leq10^7)$,求$\displaystyle\sum_{i=0}^n\sum_{j=0}^n\sum_{k=0}^n[\gcd(i,j,k)=1]$. 思路: $原式=\sum_{d=1}^n(\lfloor\frac{n}{d}\rfloor^3+3\lfloor\frac{n}{d}\rfloor^2+3\lfloor\frac{n}{d}\rfloor)\mu(d)$.数论分块即可. #include<cstdio>…
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 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…
题目链接: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 |…
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…
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}|,也就是不在坐标轴上且…
这样的点分成三类 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…
题目链接 一道比较简单的莫比乌斯反演,不过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;…
题意: 有一个\(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]) \]…