Closed lucaspbordignon closed 6 years ago
To verify if a given number is prime, simply check from 2..sqrt(n) for odd numbers, as there is no need to check more than that.
2..sqrt(n)
Finds the prime numbers that compose the given number an take the last of inserted on the set.
Note: When calling .last on a set in scala, it takes the last inserted element
.last
Benchmark
Real time: 3.335 s User time: 5.225 s Sys. time: 0.342 s CPU share: 166.93 % Exit code: 0
(You can alternatively $ time your program).
$ time
Can you git rebase master and git push -f to sync with the master branch?
git rebase master
git push -f
How the solution works
To verify if a given number is prime, simply check from
2..sqrt(n)
for odd numbers, as there is no need to check more than that.Finds the prime numbers that compose the given number an take the last of inserted on the set.
Note: When calling
.last
on a set in scala, it takes the last inserted elementPerformance
Benchmark
(You can alternatively
$ time
your program).