给定两个任意整数a和b,计算在给定范围内有多少数字可被完全数整除(a和b都是包含的)。
在数学中,一个完美数是一个正整数,它是它的适当正除数之和,即除数itself.Equivalently外的正除数之和,一个完美数是它的所有正除数之和(包括它本身)之和的一半,即σ(n) = 2n。
1 10018发布于 2014-01-17 11:27:16
朴素方法,范围大小是线性的
With[{p=#(#+1)/2&/@Select[2^Range@@Floor@Log2@Sqrt@#-1,PrimeQ]},Length@Select[Range@@#,Or@@Divisible[#,p]&]]&@Input[]正确的方法是用在给定范围内的完美数字来构造数字。
发布于 2022-10-06 13:29:39
ṡƛ'∆K=;Ḋa;∑ṡƛ'∆K=;Ḋa;∑
ṡƛ ; # Over each item x in the range [input a, input b]
'∆K=; # Keep items from the range [1, x] that are perfect numbers
Ḋa # And is x divisible by any of those perfect numbers?
∑ # Sum the number of numbers that are divisible by a perfect numberhttps://codegolf.stackexchange.com/questions/18698
复制相似问题