757 Stealthy Numbers.jl 792 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/julia
  2. # Daniel "Trizen" Șuteu
  3. # Date: 05 June 2021
  4. # https://github.com/trizen
  5. # Stealthy Numbers
  6. # https://projecteuler.net/problem=757
  7. # These are numbers of the form x*(x+1) * y*(y+1), where x and y are positive integers.
  8. # Also known as bipronic numbers.
  9. # See also:
  10. # https://oeis.org/A072389
  11. # WARNING: requires about 2GB of RAM!
  12. # Runtime: ~15 seconds.
  13. function p757(n::Int64)
  14. limit = trunc(n^(1/4))
  15. seen = Dict{Int64, Nothing}()
  16. count = 0
  17. for x in 1:limit
  18. y = x
  19. while true
  20. v = x*(x+1)*y*(y+1)
  21. v > n && break
  22. if !haskey(seen, v)
  23. count += 1
  24. seen[v] = nothing
  25. end
  26. y += 1
  27. end
  28. end
  29. return count
  30. end
  31. println(p757(10^14))