Prime Number
Md. Al-Mamun Riyadh
Prime Number
•An Integer number greater than 1 having factor one (1) and itself.
•A Prime number has exactly two factors 1 and N.
•No factor between 2 to N-1.
•No smaller factor/divisor for a Prime number N but one (1).
A Different Approach
• Let a number be N.
• How can we state that whether it is Prime or not?
• If a number N has a smaller factor/divisor than it is not a Prime
number (Composite Number).
• If a number N has a smaller factor/divisor then, of course, the
number N is a multiples of that smaller number.
• Multiples of a number is not a Prime number.
Algorithm
•Initially all the number are not multiples of other numbers.
•Let all the integer number are prime numbers.
•we are starting from two (2) as zero and one are not a prime number
by definition.
•Two (2) is a prime number.
•Multiples of Two (2) are not prime.
•Three (3) is also a prime number.
•Again multiples of Three (3) are not a prime number.
Simulation
Source: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
2 3 5 7
11 13 17 19
23 29
31 37
41 43 47
53 59
61 67
71 73 79
83 89
97
C++ Code
#include<stdio.h>
int p = 999;
bool prime[1000];
int main(){
int i,c=0;
generatePrime();
for(i=2;i<=100;i++){
if(prime[i]){
printf("%d ",i);
c++;
}
}
printf("nPrime: %d",c);
return 0;
}
void generatePrime(){
int i,j;
prime[0]=prime[1]=false;
for(i=2;i<=p;i++)
prime[i]=true;
for(i=2;i*i<=p;i++){
if(prime[i]){
for(j=i*i;j<=p;j+=i)
prime[j]=false;
}
}
}
Sieve of Eratosthenes
Source: https://en.wikipedia.org/wiki/Sieve_theory
Thank you
Q/A
Prime Number (Sieve)

Prime Number (Sieve)

  • 2.
  • 3.
    Prime Number •An Integernumber greater than 1 having factor one (1) and itself. •A Prime number has exactly two factors 1 and N. •No factor between 2 to N-1. •No smaller factor/divisor for a Prime number N but one (1).
  • 4.
    A Different Approach •Let a number be N. • How can we state that whether it is Prime or not? • If a number N has a smaller factor/divisor than it is not a Prime number (Composite Number). • If a number N has a smaller factor/divisor then, of course, the number N is a multiples of that smaller number. • Multiples of a number is not a Prime number.
  • 5.
    Algorithm •Initially all thenumber are not multiples of other numbers. •Let all the integer number are prime numbers. •we are starting from two (2) as zero and one are not a prime number by definition. •Two (2) is a prime number. •Multiples of Two (2) are not prime. •Three (3) is also a prime number. •Again multiples of Three (3) are not a prime number.
  • 6.
    Simulation Source: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes 2 35 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
  • 7.
    C++ Code #include<stdio.h> int p= 999; bool prime[1000]; int main(){ int i,c=0; generatePrime(); for(i=2;i<=100;i++){ if(prime[i]){ printf("%d ",i); c++; } } printf("nPrime: %d",c); return 0; } void generatePrime(){ int i,j; prime[0]=prime[1]=false; for(i=2;i<=p;i++) prime[i]=true; for(i=2;i*i<=p;i++){ if(prime[i]){ for(j=i*i;j<=p;j+=i) prime[j]=false; } } }
  • 8.
    Sieve of Eratosthenes Source:https://en.wikipedia.org/wiki/Sieve_theory
  • 9.

Editor's Notes

  • #2 Good Morning Everyone. I welcome you all to my presentation on Prime Number.
  • #3 I am Md. Al-Mamun Riyadh. Let’s introduce with Prime Number.
  • #4 Prime Number is an Integer number greater than 1 having factor one and itself. From this statement, we can conclude that a prime number, for example, N has exactly two factors 1 and n. Therefore there is no factor between 2 to n-1 for a number N. We can alternatively say that there is no smaller factor/divisor for a prime number N but one. From the given definition we can find whether a number is prime or not by using the divisibility properties of a number. But those solutions are not time efficient. I am discussing a different approach to find the prime numbers.
  • #5 Let a number be N. How can we state that whether it is prime or not? Our solution was if a number N has a smaller factor/divisor than it is not a prime number, we can call it composite Number. but now we will not consider in this way. we will think oppositely. if a number N has a smaller factor/divisor then, of course, the number N is a multiples of that smaller number. (and it is not a prime Number) therefore we can say multiples of any integer number is not a prime number.
  • #6 Let initially all the number are not multiples of other numbers. More easily we can say, initially let all the integer number are a prime number. obviously, we are starting from two (2) as zero and one are not a prime number by definition. so in the beginning, two (2) is a prime number. therefore multiples of two are not prime. we will use a marker variable in our program to trace the newly found composite number. we will go for three as it also a prime number as we defined earlier. Again multiples of three are not a prime number. we will mark those as a composite number.
  • #7 This is the visual simulation of this algorithm taken from Wikipedia. I also give a list of first 25 prime number from 1 up to 100
  • #8 This is the c++ code for this algorithm. In the given example I demonstrate a time efficient prime number generating algorithm. We are also able to make it more memory efficient code for this algorithm. In the general solution using divisibility properties, time complexity determines whether a number prime or not was an order of sqrt(n). but in this algorithm, it is O(1). and for the first time to generate all prime number list complexity of the sieve function is O(log(log(n))
  • #9 Actually, the name of this algorithm is Sieve of Eratosthenes. Eratosthenes was a Greek mathematician who designs this algorithm to generate the prime number faster than other approaches.
  • #10 thank you, everyone, for joining me in this presentation. you may ask your query if any, please.