zoj 3435 spoj 7001 莫比乌斯反演

zoj 3435

题意:

给出3个数a,b,c, 定义一个立方体,这个立方体有a*b*c个点,每个点的坐标都是整数(x,y,z),求经过坐标(1,1,1)和另外任意一个点(x1,y1,z1)的不同的直线有多少条。

限制:

2 <= a,b,c <= 1e6; 有200组数据。

思路:

有3种情况:

1. x1,y1,z1都大于等于2:

问题就变成求1 <= x <= a-1 && 1 <= y <= b-1 && 1 <= z <= c-1 && gcd(x,y,z)=1的三元组有多少对。

用莫比乌斯反演来做。

设f(k)为gcd(x,y,z)=k的三元组(x,y,z)的数目,

设F(k)为gcd(x,y,z)为k的倍数的三元组(x,y,z)的数目,所以F(k)=floor((a-1)/k)*floor((b-1)/k)*floor((c-1)/k),然后加上一个分段就可以解决了。

2. x1,y1,z1中有1个为1

然后问题就退化成2为的互质问题了,同样可以用莫比乌斯反演来做。

3. x1,y1,z1中有2个为1

有3条直线。

分别考虑好3种情况后加起来即可。

spoj 7001 和上面那道题差不多

时间: 2024-10-06 22:22:14

zoj 3435 spoj 7001 莫比乌斯反演的相关文章

SPOJ 7001(莫比乌斯反演)

传送门: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) )

spoj 4491 莫比乌斯反演

题意: 给出a,b,求gcd(x,y)=prime的方案数,其中:1 <= x <= a && 1 <= y <= b 限制: 1 <= a,b <= 1e7 思路: 先把问题拆成一个一个来考虑,然后问题就变成gcd(x,y)=k的方案数. 设f(k)为gcd(x,y)=k的方案数, 设F(k)为gcd(x,y)为k的倍数的方案数,显然F(k)=floor(a/k)*floor(b/k). 由莫比乌斯反演得: f(k)=mu[1]*F[k]+mu[2]*

SPOJ VLATTICE 莫比乌斯反演

题目链接:https://www.spoj.com/problems/VLATTICE/en/ VLATTICE - Visible Lattice Points Description Consider a NNN 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

bzoj 2820 / SPOJ PGCD 莫比乌斯反演

那啥bzoj2818也是一样的,突然想起来好像拿来当周赛的练习题过,用欧拉函数写掉的. 求$(i,j)=prime$对数 \begin{eqnarray*}\sum_{i=1}^{n}\sum_{j=1}^{m}[(i,j)=p]&=&\sum_{p=2}^{min(n,m)}\sum_{i=1}^{\lfloor\frac{n}{p}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{p}\rfloor}[i⊥j]\newline&=&\sum_{p=

SPOJ PGCD(莫比乌斯反演)

传送门:Primes in GCD Table 题意:给定两个数和,其中,,求为质数的有多少对?其中和的范围是. 分析:这题不能枚举质数来进行莫比乌斯反演,得预处理出∑υ(n/p)(n%p==0). #pragma comment(linker,"/STACK:1024000000,1024000000") #include <cstdio> #include <cstring> #include <string> #include <cmat

spoj 7001 Visible Lattice Points莫比乌斯反演

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

SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演 难度:3

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}|,也就是不在坐标轴上且

[SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演

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

【BZOJ2226】[Spoj 5971] LCMSum 莫比乌斯反演(欧拉函数?)

[BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i and n. Input The first line contains T the number of test cases. Each of the n