485 Maximum number of divisors.jl 743 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/julia
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 21 February 2017
  5. # https://github.com/trizen
  6. # https://projecteuler.net/problem=485
  7. # Runtime: 4 min, 41 sec.
  8. using Primes
  9. @inline function sigma0(n)
  10. prod(map((v)-> 1+v, values(factor(n))))
  11. end
  12. function p485(r, n)
  13. divisors = map((k)->sigma0(k), 1:r)
  14. range_max = maximum(divisors)
  15. total = 0
  16. for i in r+1 : n+1
  17. total += range_max
  18. d = sigma0(i)
  19. if (d > range_max)
  20. range_max = d
  21. end
  22. append!(divisors, d)
  23. if (popfirst!(divisors) == range_max)
  24. range_max = maximum(divisors)
  25. end
  26. end
  27. return total
  28. end
  29. #println(p485(10, 1000))
  30. println(p485(100_000, 100_000_000))