225 Tribonacci non-divisors.jl 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/julia
  2. # Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 06 May 2017
  5. # https://github.com/trizen
  6. # https://projecteuler.net/problem=225
  7. # Runtime: 3.249s
  8. function p_225(nth=124)
  9. a,c,k = 0,1,1
  10. while (c <= nth)
  11. cache = Dict{Int64, Int64}()
  12. function tribonacci(n)
  13. n <= 3 ? 1 :
  14. haskey(cache, n) ? cache[n] : cache[n] = (
  15. tribonacci(n - 1) % k
  16. + tribonacci(n - 2) % k
  17. + tribonacci(n - 3) % k
  18. ) % k
  19. end
  20. n = 4
  21. while true
  22. t1 = tribonacci(n)
  23. t2 = tribonacci(n+1)
  24. t3 = tribonacci(n+2)
  25. if (t1 == 1 && t2 == 1 && t3 == 1)
  26. a = k
  27. c += 1
  28. break
  29. end
  30. if (t1 == 0 || t2 == 0 || t3 == 0)
  31. break
  32. end
  33. n += 3
  34. end
  35. k += 2
  36. end
  37. return a
  38. end
  39. println(p_225())