Introduction to prime number algorithm:
A prime number is a positive natural number with no other divisors except one and itself but the number 1 is excluded by definition. That is to say one is not a prime number. That leaves us with the first prime number as 2 and it is quite obvious that all other prime numbers after 2 have to be odd numbers only. The concept of prime numbers has fascinated mathematicians from the earliest times. Euclid proved infinitude of prime numbers as early as 300 B.C. There have been many failed attempts to find a formula that will generate prime numbers. A search for efficient algorithms to find prime numbers gained momentum with the advent of computers and today many efficient programs exist to calculate prime numbers limited only by the processor memory and speed.
Finding Prime Numbers by Division:
In order to check whether a given number n is a prime or not, it has to be divided one by one by all prime numbers less than `sqrt(n)`. The reasoning is simple; if the number is not a prime then there will be at least one prime factor which is less than `sqrt(n)`. This can be used to create a simple algorithm for checkng numbers one by one and discarding compound numbers will leave a list of prime numbers.
In simple language we can write the algorithm as:
Take numbers 2 to N (one by one). Let the number by x
Divide x by all prime numbers less than or equal to `sqrt(x)`
If it is divisible by any of the prime numbers, discard it as non-prime and go to next number.
Simple! Isn't it? But it is not a very useful algorithm for use with computers, where too much processor is lost in division operation at every stage of this algorithm. Processors are more comfortable with read and write commands and simple addition and substraction operations. It is interesting to note that one of the oldest algorithms Sieve of Eratosthenes is one of the efficient algorithms for use with modern computers.
Between, if you have problem on these topics Numerical Expression Examples, please browse expert math related websites for more help on Calculating Profit Percentage.
Sieve of Eratosthenes of Prime Number Algorithm:
Concept behind this prime number algorithm is quite simple and uses tool of skip counting learnt by all of us in elementary school. It has only two steps. Write all the numbers up to a specified number. 2 is a prime, so after 2 strike out every second number. Next is 3 again a prime, so after 3 strike out every third number; and so on. Every time you complete the process for a prime p, you would be left with only primes up to the number p2.
Step 1:
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
Step 2: Striking out every second, then every third and then every fifth number, we are left with prime numbers less than 52 = 25 (shown in bold).
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
We are left with prime numbers up to 25 as: 2, 3, 5, 7, 11, 13, 17, 19, 23.
It is interesting to note that this algorithm is found quite suitable for listing prime numbers using present day computing devices.
A prime number is a positive natural number with no other divisors except one and itself but the number 1 is excluded by definition. That is to say one is not a prime number. That leaves us with the first prime number as 2 and it is quite obvious that all other prime numbers after 2 have to be odd numbers only. The concept of prime numbers has fascinated mathematicians from the earliest times. Euclid proved infinitude of prime numbers as early as 300 B.C. There have been many failed attempts to find a formula that will generate prime numbers. A search for efficient algorithms to find prime numbers gained momentum with the advent of computers and today many efficient programs exist to calculate prime numbers limited only by the processor memory and speed.
Finding Prime Numbers by Division:
In order to check whether a given number n is a prime or not, it has to be divided one by one by all prime numbers less than `sqrt(n)`. The reasoning is simple; if the number is not a prime then there will be at least one prime factor which is less than `sqrt(n)`. This can be used to create a simple algorithm for checkng numbers one by one and discarding compound numbers will leave a list of prime numbers.
In simple language we can write the algorithm as:
Take numbers 2 to N (one by one). Let the number by x
Divide x by all prime numbers less than or equal to `sqrt(x)`
If it is divisible by any of the prime numbers, discard it as non-prime and go to next number.
Simple! Isn't it? But it is not a very useful algorithm for use with computers, where too much processor is lost in division operation at every stage of this algorithm. Processors are more comfortable with read and write commands and simple addition and substraction operations. It is interesting to note that one of the oldest algorithms Sieve of Eratosthenes is one of the efficient algorithms for use with modern computers.
Between, if you have problem on these topics Numerical Expression Examples, please browse expert math related websites for more help on Calculating Profit Percentage.
Sieve of Eratosthenes of Prime Number Algorithm:
Concept behind this prime number algorithm is quite simple and uses tool of skip counting learnt by all of us in elementary school. It has only two steps. Write all the numbers up to a specified number. 2 is a prime, so after 2 strike out every second number. Next is 3 again a prime, so after 3 strike out every third number; and so on. Every time you complete the process for a prime p, you would be left with only primes up to the number p2.
Step 1:
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
Step 2: Striking out every second, then every third and then every fifth number, we are left with prime numbers less than 52 = 25 (shown in bold).
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
We are left with prime numbers up to 25 as: 2, 3, 5, 7, 11, 13, 17, 19, 23.
It is interesting to note that this algorithm is found quite suitable for listing prime numbers using present day computing devices.
No comments:
Post a Comment