aboutsummaryrefslogtreecommitdiff
path: root/julia/003-largest_prime_factor.jl
diff options
context:
space:
mode:
Diffstat (limited to 'julia/003-largest_prime_factor.jl')
-rw-r--r--julia/003-largest_prime_factor.jl25
1 files changed, 25 insertions, 0 deletions
diff --git a/julia/003-largest_prime_factor.jl b/julia/003-largest_prime_factor.jl
new file mode 100644
index 0000000..01e71cf
--- /dev/null
+++ b/julia/003-largest_prime_factor.jl
@@ -0,0 +1,25 @@
+###
+# Largest prime factor
+# Problem 3
+#
+# The prime factors of 13195 are 5, 7, 13 and 29.
+# What is the largest prime factor of the number 600851475143 ?
+###
+
+const NUMBER = 600851475143
+
+function factors(n)
+ factors = []
+ while n > 1
+ for d in 2:n
+ if n % d == 0
+ n = Int64(n / d)
+ push!(factors, d)
+ break
+ end
+ end
+ end
+ factors
+end
+
+println(maximum(factors(NUMBER)))