uk702 发表于 2021-1-9 11:58:20

本帖最后由 uk702 于 2021-1-9 12:06 编辑

mathe 发表于 2021-1-8 17:32
前面弄错了,30个数才到0.228800,40个数到0.229411,50个数到0.229762,60个数到0.230061

我用 julia 写了程序楞算,概率至少 > 0.232323,并且不是随着 n 增加而严格递增
n = 10000000, t = 0.2322919
n = 11000000, t = 0.2322950909090909
n = 12000000, t = 0.23229758333333334
n = 13000000, t = 0.23229561538461538
n = 14000000, t = 0.2322962142857143
n = 15000000, t = 0.23229826666666667
n = 16000000, t = 0.232299125
n = 17000000, t = 0.23229911764705882
n = 18000000, t = 0.23230083333333335
n = 19000000, t = 0.23230373684210526
n = 20000000, t = 0.23230505
n = 21000000, t = 0.23230633333333334
n = 22000000, t = 0.23230577272727274
n = 23000000, t = 0.2323062608695652
n = 24000000, t = 0.232308625
n = 25000000, t = 0.23230984
n = 26000000, t = 0.23230926923076922
n = 27000000, t = 0.23230948148148148
n = 28000000, t = 0.23231017857142858

using Primes

function factors(n)
    f =
    for (p,e) in factor(n)
      f = reduce(vcat, , init=f)
    end
    return length(f) == 1 ? : sort!(f)
end

t = 0
i = 1
while true
    a = factors(i)
    for u=1:length(a)
      for v=u+1:length(a)
            if a+a in a
                # println((i, a, a))
                global t = t+1
                @goto _next
            end   
      end   
    end

@label _next
global i=i+1
if i % 1000000 == 0 println("n = $i, t = $(t/i)") end
end
页: 1 [2]
查看完整版本: 求和谐数的比例