Calculating a large sum of positive and negative integers gives wrong answer

Just a few comments:

Are you on a 32-bit system, because on mine, there’s no primes method for Int32:

julia> primes(Int32(11))
ERROR: MethodError: no method matching primes(::Int32)

Closest candidates are:
  primes(::Int64)
   @ Primes C:\Users\DNF\.julia\packages\Primes\Yo1YT\src\Primes.jl:130
  primes(::Int64, ::Int64)
   @ Primes C:\Users\DNF\.julia\packages\Primes\Yo1YT\src\Primes.jl:114

I was wondering why you wrapped your literals like this: Int64(2), since that’s not normally needed.

Secondly, it’s safer to use isqrt(n) rather than floor(Int, sqrt(n)). I struggled a bit to find an example, but here’s one from an old thread using an Int128:

1 Like