133 Repunit nonfactors.jl 763 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/julia
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 14 May 2017
  5. # https://github.com/trizen
  6. # https://projecteuler.net/problem=133
  7. # Runtime: 2 min, 5 sec
  8. using Primes
  9. function p_133()
  10. factors = Dict{Int64, Bool}()
  11. limit = 100_000
  12. p = 10
  13. while (p < limit)
  14. p += 1
  15. isprime(p) || continue
  16. k,s,P = 0,0,0
  17. while (k <= p)
  18. s += powermod(10, k, p)
  19. s %= p
  20. P += 1
  21. s == 0 && break
  22. k += 1
  23. end
  24. if (s == 0 && powermod(10, k, P) == 0)
  25. factors[p] = true
  26. println("$p is a prime factor (period: $P)")
  27. end
  28. end
  29. return sum(filter((p) -> !haskey(factors, p), primes(limit)))
  30. end
  31. println(p_133())