SPOJ-7001 VLATTICE 莫比乌斯反演定理】的更多相关文章

题目链接: http://www.spoj.com/problems/VLATTICE/ 题意: 1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1 分析: 欧拉搞不了了,我们用莫比乌斯来搞一搞. 同样,我们设 f(d):满足gcd(x,y,z)=d且x,y,z均在给定范围内的(x,y,z)的对数. F(d):满足d|gcd(x,y,z)且x,y,z均在给定范围内的(x,y,z)的对数. 显然F(d)=[n/d][n/d][n/d],反演后我们得到 f(x)=∑x|dμ(d…
题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(x,y,z)=1,1<=x,y,z<=n,的个数. 开始做的时候枚举gcd(x,y),然后求z与gcd(x,y)互素的个数个数,O(n*sqrt(n))赌赌RP,然后TLE了... 后来才知道要用到莫比乌斯反演定理: 已知 f(n) = sigma(d|n, g(d)) 那么 g(n) = sigma(d|n, mu(d)*f(n/d)) 还有另一种形式更常用: 在某一范围内,已知 f(n)…
题目链接: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 |…
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…
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://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…
传送门:Visible Lattice Points 题意:0<=x,y,z<=n,求有多少对xyz满足gcd(x,y,z)=1. 设f(d) = GCD(a,b,c) = d的种类数 : F(n) 为GCD(a,b,c) = d 的倍数的种类数, n%a == 0 n%b==0 n%c==0. 即 :F(d) = (N/d)*(N/d)*(N/d); 则f(d) = sigma( mu[n/d]*F(n), d|n ) 由于d = 1 所以f(1) = sigma( mu[n]*F(n) )…
题意:求一个正方体里面,有多少个顶点可以在(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…
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…
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 segment joining X and Y. Inpu…