include("euler.jl")
function p3(n = 600851475143)
prime_factors(n) |> maximum
Euler.end;
p3()
WARNING: replacing module Euler.
6857
include("euler.jl")
function p3(n = 600851475143)
prime_factors(n) |> maximum
Euler.end;
p3()
WARNING: replacing module Euler.
6857
using BenchmarkTools;
@benchmark p3()
BenchmarkTools.Trial: 10000 samples with 1 evaluation. Range (min … max): 15.578 μs … 39.393 μs ┊ GC (min … max): 0.00% … 0.00% Time (median): 15.669 μs ┊ GC (median): 0.00% Time (mean ± σ): 16.353 μs ± 1.768 μs ┊ GC (mean ± σ): 0.00% ± 0.00% █▆▂ ▁▂▂▁▁ ▁ ▁ ███▇█▅▄▅▅▇▃▅▃▅▄▄▅▄▄▅▅▅▇▅▃▄▄▅▁▁▅▇███████▇▅▆▆▇▇████████▇▇▆▇▇▇ █ 15.6 μs Histogram: log(frequency) by time 22.1 μs < Memory estimate: 144 bytes, allocs estimate: 2.
include("euler.jl")
function p3()
= 600851475143
n
# get all primes lesses than sqrt(n)
= Euler.sieve_of_eratosthenes(isqrt(n)) # see prelude
possible_primes
# get the biggest one
= findlast(x -> n % x == 0, possible_primes)
id return possible_primes[id]
end;
p3()
WARNING: replacing module Euler.
6857
using BenchmarkTools;
@benchmark p3()
BenchmarkTools.Trial: 1966 samples with 1 evaluation. Range (min … max): 2.255 ms … 4.357 ms ┊ GC (min … max): 0.00% … 20.66% Time (median): 2.458 ms ┊ GC (median): 0.00% Time (mean ± σ): 2.542 ms ± 224.887 μs ┊ GC (mean ± σ): 2.84% ± 5.96% ▅▇█▄▄▂▁ ▁▁▁▁▂▃▇███████▆▅▄▄▃▂▂▂▂▂▂▁▁▁▂▁▂▁▁▁▁▂▁▁▂▂▂▃▂▂▂▂▂▂▁▂▁▁▁▁▁▁▁▁▁ ▂ 2.26 ms Histogram: frequency by time 3.31 ms < Memory estimate: 6.48 MiB, allocs estimate: 8.