algorithm - 从 1 到 N 有多少对 LCM = N?

标签 algorithm number-theory lcm

假设N = 8。有4对(1,8),(2,8),(4,8),(8,8),其LCM为8。如果N = 6。则有5对(1,6),(2,6),(2,3),(3,6),(6,6) LCM为6。现在想知道如何快速求对数?

最佳答案

问题"Pairs of numbers with at given LCM"在 math.stackexchange.com 上给出了公式

((2e1+1)(2e2+1)...(2ek+1)+1)/2
        where e1, e2, ... is the exponents for the unique prime factors of n

对于这个数字。


8 = 2^3 有 ((2*3+1)+1)/2 = 4 个这样的对,
6 = 2^1 * 3^1 有 ((2*1+1)(2*1+1)+1)/2 = 5 个这样的对,并且
60 = 2^2 * 3^1 * 5^1 有 ((2*2+1)(2*1+1)(2*1+1)+1)/2 = 23 个这样的对。

关于algorithm - 从 1 到 N 有多少对 LCM = N?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39558111/

相关文章:

python - 如何找到阈值内最长的子数组?

c - C 程序在查找整数三元组 (x,y,z) 时出错,使得 n^x + n^y = n^z 对于给定的 n 范围

algorithm - 找出两点之间的最大距离

c++ - 较大值的答案溢出

algorithm - 细胞探针模型

algorithm - 来自 "Programming Pearls"的方程式 - 有人可以解释一下吗?

c++ - 3D 碰撞分辨率,移动 AABB + 多面体

python - Schonhage-Strassen 乘法实现错误

c - 求C中两个数的LCM

algorithm - 3个或更多数字的最小公倍数