0

how to check big prime numbers in Java

how to check big prime numbers in Java

6th Feb 2017, 3:55 PM
Avinash Jha
Avinash Jha - avatar
3 Respuestas
+ 7
Inspired by James' answer: https://code.sololearn.com/cUsgvP1qFvW4/?ref=app I didn't search for optimized algorithms, so it's just a little messy code and not mind blowing 😊
4th Mar 2017, 10:57 AM
Tashi N
Tashi N - avatar
+ 1
There are quite a lot of good algorithms out there for finding out if a number is a prime. I would start by checking if the number is divisible by two, if it's not then check all of the odd numbers from 3 to the square root of the number. This isn't the best algorithm but it's a start. You can then do some tricks like memoization that can trade memory for runtime.
6th Feb 2017, 4:23 PM
James Durand
James Durand - avatar
22nd Jul 2017, 12:13 PM
Mahdi sg
Mahdi sg - avatar