Advertisement
zvoulgaris

Untitled

May 22nd, 2020
2,724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.56 KB | None | 0 0
  1. # Euler 87 drill
  2.  
  3. using Primes
  4.  
  5. function main(n::Int64 = 50, verbose::Bool = false)
  6.     P1 = primes(floor(Int64, sqrt(n)))
  7.     P2 = primes(floor(Int64, n^(1/3)))
  8.     P3 = primes(floor(Int64, n^0.25))
  9.     c = 0
  10.  
  11.     for p1 in P1
  12.         for p2 in P2
  13.             for p3 in P3
  14.                 z = p1^2 + p2^3 + p3^4
  15.  
  16.                 if z <= n
  17.                     c += 1
  18.                     if verbose; println(z, " = ", p1, "^2 + ", p2, "^3 + ", p3, "^4"); end
  19.                 end
  20.             end
  21.         end
  22.     end
  23.  
  24.     println("")
  25.     return c
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement