0
Prime Numbers
What are Prime Numbers?
7 Antworten
+ 2
If you want to know all prime numbers, you have to test if the number can be divided by any other number without any remainder.
A prime number, by definition, is divisible by exactly two numbers. Divisible by 1 and divisible by itself. By definition, 1 cannot be prime because it is only divisible by one number. 2 is a prime number because it can be divided by 1 and by itself, 2.
To test if a number is prime, try to divide that number by every number smaller than itself. For efficiency, you only have to test divisors less than half the original number.
So to try it an example: 17
17 % 2 == 0 fails (all even numbers ruled out on this test)
17 % 3 == 0 fails
17 % 5 == 0 fails
17 % 7 == 0 fails
no point in testing against even numbers because all even numbers produce even results.
no point to testing higher than 7 because more than half the value of the target will never divide evenly.
Since it gets harder to find a prime number as the number gets higher, there have been efforts by programmers to find the highest possible prime number. Currently the highest prime number ever calculated is 41,024,320 digits long. It is 2 to the power of 136,279,841 minus 1.
Due to modern processors having limits to the size of numbers it can do math on, it takes special techniques to perform the necessary calculations. Your PC cannot process digits that long. A modern 64 bit processor can handle 2 to the power of 64 minus 1. So don't even try to beat the world record on a standard PC or Mac unless you want to write your own virtual CPU that can manually handle numbers of massive size.
I wrote a simple prime number generator here: https://www.sololearn.com/en/compiler-playground/cRcsg38FV3vU
Someday I will optimize it and see how far I can go within SoloLearn's CPU restrictions.
+ 1
Prime numbers are all numbers greater than 1 that are only divisible by 1 and themselves.
e.g. 2,3,5,7,11,13,17...
+ 1
Zvi absolutely. Maybe someone else will read this and think, “Wow! That’s cool stuff.” lol
+ 1
Jerry Hobby
Wow! That's cool stuff. 😎
I also have something prime related ..
https://sololearn.com/compiler-playground/cpk4ClKbYN1n/?ref=app
+ 1
Bob_Li How you did that with regex… Mind boggling!
0
Jerry Hobby
I think the OP just wanted to know what prime numbers are. I think you’re getting a little carried away🤪.
0
Jerry Hobby
There's a link to the YouTube video I was watching at a comment on the top of the code.
# from a Matt Parker video
https://www.youtube.com/watch?v=5vbk0TwkokM