What language is this?
if it's Haskell, what's 'Safe'?
Challenge
Haskell.
hackage.haskell.org
Safe is a haskell package which takes partial functions from the Prelude and offers total variants of them. For example head from the Prelude is a partial function. If you pass an empty list into head, your program will crash. The Safe package offers a headMay function which will wrap the return type in a Maybe. This means instead of crashing on an empty list, it simply returns Nothing.
Haskell is such a bad meme. Here I rewrote it so you can read it without contracting braindamage: fn solve(n: u64) -> u64 { (2..n).filter(|i| n % i == 0).next() .map_or(n, |i| solve(n / i))}
Without math you'll always be a subpar computer scientist and a low ranking programmer.
sudo apt remove chrome* *google* fonts-noto*
sudo apt remove javascript-common
sudo apt remove rust* libstd-rust* cargo*
sudo apt remove snapd* libsnapd*
You should also do
sudo apt remove apt
sudo apt install guix
sudo apt kys retard
Start with your large number, and divide out (completely) successively larger factors (from 2 onwards). Each divisor you try will necessarily be prime, otherwise one of the previous divisors would have gone into it. It turns out that in this problem, each prime factor only goes in once, ie 600851475143 = p1*p2*p3... all have multiplicity 1, they're not raised to any powers.
71 is the first number to divide into 600851475143, now divide that out,
600851475143 / 71 = 8462696833 If 71 divided in multiple times, we'd repeatedly divide by 71. We now try dividing 8462696833 by 72 onwards. Do you see why 8462696833 couldn't be divisible by any previous factor? Continue this process until the large number is reduced to 1. The last divisor we use will be the greatest prime factor.
600851475143 / 71 = 8462696833
8462696833 / 839 = 10086647
10086647 / 1471 = 6857
6857 / 6857 = 1. [Done]
As you can see, not many divisions are necessary, the number reduces quite quickly.
Pardon me, that should be each proper divisor you try, will necessarily be prime. 72 for instance is not a proper divisor of 8462696833, so you try 73, 74... onwards to 839.
cringe
just link to wikipedia next time
en.wikipedia.org
even easier, just explain what
is doing