133 Repunit nonfactors -- v2.jl 992 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/julia
  2. # Daniel "Trizen" Șuteu
  3. # Date: 16 November 2021
  4. # https://github.com/trizen
  5. # https://projecteuler.net/problem=133
  6. # Runtime: 1.137s
  7. using Primes
  8. function divisors(n)
  9. d = Int64[1]
  10. for (p,e) in factor(n)
  11. t = Int64[]
  12. r = 1
  13. for i in 1:e
  14. r *= p
  15. for u in d
  16. push!(t, u*r)
  17. end
  18. end
  19. append!(d, t)
  20. end
  21. return sort(d)
  22. end
  23. function prime_znorder(a, n)
  24. for d in divisors(n-1)
  25. if (powermod(a, d, n) == 1)
  26. return d
  27. end
  28. end
  29. end
  30. function p_133()
  31. factors = Dict{Int64, Nothing}()
  32. limit = 100_000
  33. N = 10^floor(Int64, log2(big(limit)))
  34. for p in primes(7, limit)
  35. if (rem(N, prime_znorder(10, p)) == 0)
  36. factors[p] = nothing
  37. end
  38. end
  39. total = 0
  40. for p in primes(limit)
  41. if !haskey(factors, p)
  42. total += p
  43. end
  44. end
  45. return total
  46. end
  47. println(p_133())