193 Squarefree Numbers.sf 371 B

12345678910111213141516
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # Date: 09 February 2017
  4. # https://github.com/trizen
  5. # Squarefree Numbers
  6. # https://projecteuler.net/problem=193
  7. # Formula for counting the number of squarefree numbers <= n:
  8. # S(n) = Sum_{k=1..floor(sqrt(n))} moebius(k) * floor(n/k^2)
  9. # Runtime: 0.291s (previously: ~6 seconds).
  10. say squarefree_count(2**50) # built-in