假设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/