The sequence of prime numbers never ends. They have several properties that make them special - here are just a few of them. Prime numbers may seem like just a new quirk, but mathematicians have been fascinated with them for millennia (as we’ll see in a bit). Looking for prime number is a common exercise not just in mathematics, but also in programming, where the goal is learning how to devise and optimize an algorithm.Ī list of prime numbers up to one thousand: We can get even smarter than this: you don’t even need to check until half of the number, you only need to check to its square root (√n). So you don’t need to look further than the half of the number. If you reach a number beyond ‘half’ of n’s value, you’d need to multiply it by something smaller - but there’s nothing smaller than 2. every number can be written as: number (n) = ‘half’ x 2.You don’t need to check every number from 2 to 100, you can stop with your checks at 50, which is the half of 100. For instance, let’s say you want to check if the number 100 is prime (spoiler alert, it’s not). You can get a bit more clever with your prime-finding sieves too. You can see a visual representation of how it works in the image below: This is called a ‘sieve’, and commonly, the ‘sieve of Eratosthenes’, since the ancient Greek mathematician Eratosthenes first described it. So we can just move on to 5, 7, and move on. You don’t need to use ‘4’ since it is an even number, and we already know that other than ‘2’, no prime number is even. This is actually a very old algorithm used to discover prime numbers: you start from 2, and then every prime number you encounter, you use it to weed out its multiples. For instance, ‘3’ is a prime number, so it can be used to weed out other numbers that aren’t prime. With the odd numbers, we can use a similar approach, but using other numbers instead of ‘2’. The number ‘2’ is the only even prime number. Even numbers are divisible by 2, which means they can be written as 2 times something - and are therefore composite, not prime. Every number is either odd or even, by definition. We can weed out half of them right from the start. Demonstration, with Cuisenaire rods, that 7 is prime, because none of 2, 3, 4, 5, or 6 divide it evenly.īut we can get a bit more clever about our search for prime numbers. In other words, if it has any divisors other than 1 and itself, it’s not prime. The rough way to search for prime numbers is to take any number and try and see if any numbers divide it evenly. ADVERTISEMENT Checking if a number is a prime
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |