R すなわち以下の仕様では
R version 4.1.1 Patched (2021-09-05 r80862)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.6
system.time({
library(gmp)
func <- function(n) {
x <- (n+1):(2*n)
y <- n*x/(x-n)
count <- sum(floor(y) == y)
return(count)
}
n <- 2
while (n <= 180190) {
if (func(n) > 1000) {
print(n)
break
}
n <- n+1
}
})
[1] 180180
user system elapsed
121.496 32.980 154.516
#####
Julia 1.6.3 M1 チップ非対応では,
function func(n)
x = (n+1):(2*n)
y = n .*x ./ (x .- n)
sum(floor.(Int, y) .== y)
end
function f()
n = 2
while n <= 180190
if func(n) > 1000
println(n)
break
end
n += 1
end
end
@time f()
# 180180
# 68.376876 seconds (947.74 k allocations: 123.598 GiB, 2.28% gc time)
まあ,2倍くらい速い。
#####
Julia 1.7.0 M1 チップ対応ではあるが開発途上,ではさらに速い
@time f()
# 180180
# 39.769370 seconds (971.07 k allocations: 123.592 GiB, 9.96% gc time, 0.03% compilation time)
#####
ちなみに,Python 3.10 でもやってみようと思ったが,動かし方を忘れてしまった。