|
发表于 2024-4-15 05:56:54
|
显示全部楼层
先佩服一下你的刨根问底的精神。这个帖是我犯的一个错误,搞了这么无聊的一出算法来。
- function calcN(n::Int64) t1 = time() ans::Int64 = 0 for a1=1:div(n, 8) r1 = n - a1 for a2=a1:div(r1, 7) r2 = r1 - a2 for a3=a2:div(r2, 6) r3 = r2 - a3 for a4=a3:div(r3, 5) r4 = r3 - a4 for a5=a4:div(r4, 4) r5 = r4 - a5 for a6=a5:div(r5, 3) r6 = r5 - a6 for a7=a6:div(r6, 2) a8=r6 - a7 ans += xor(xor(xor(a1, a2), xor(a3, a4)), xor(xor(a5, a6), xor(a7, a8))) end end end end end end end println("n=$n, ans = $ans, cost = $(time() -t1)")endcalcN(100);calcN(160);calcN(300);calcN(400);calcN(500);calcN(600);calcN(700);calcN(800);calcN(900);calcN(1000); $ julia wl.jln=100, ans = 29892426, cost = 0.0009999275207519531sn=160, ans = 901994896, cost = 0.013000011444091797sn=300, ans = 109638857854, cost = 0.5759999752044678sn=400, ans = 1260273347474, cost = 3.486999988555908sn=500, ans = 6722928203618, cost = 14.36300015449524sn=600, ans = 25125831176186, cost = 46.539000034332275s
复制代码 |
|