SlideShare a Scribd company logo
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)

More Related Content

What's hot

Arrays
ArraysArrays
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Priority queues
Priority queuesPriority queues
Priority queues
Priyanka Rana
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programingrupali_2bonde
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Searching
SearchingSearching
Searching
Ashim Lamichhane
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Data structures using c
Data structures using cData structures using c
Data structures using c
Prof. Dr. K. Adisesha
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 

What's hot (20)

Arrays
ArraysArrays
Arrays
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Priority queues
Priority queuesPriority queues
Priority queues
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
 
Array data structure
Array data structureArray data structure
Array data structure
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Searching
SearchingSearching
Searching
 
2D Array
2D Array 2D Array
2D Array
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 

Similar to Prime Number (Sieve)

Presentation on Prime Numbers and Composite Numbers
Presentation on Prime Numbers and Composite NumbersPresentation on Prime Numbers and Composite Numbers
Presentation on Prime Numbers and Composite Numbers
cybershackshillong
 
Intengers!.pptx
Intengers!.pptxIntengers!.pptx
Intengers!.pptx
JeniEstabaya
 
1672631 634959625708535000
1672631 6349596257085350001672631 634959625708535000
1672631 634959625708535000Nisha Prasad
 
BInary Number Representation
 BInary Number Representation BInary Number Representation
BInary Number Representation
Srikrishna Thota
 
Numeral System
Numeral SystemNumeral System
Power point presentation {nazareth}
Power point presentation {nazareth}Power point presentation {nazareth}
Power point presentation {nazareth}tayln
 
Real basic define arivu
Real basic define arivuReal basic define arivu
Real basic define arivu
ARIVUSELVID
 
om kamthe power.pptx
om kamthe power.pptxom kamthe power.pptx
om kamthe power.pptx
omkamthe2
 
Prime number generation
Prime number generationPrime number generation
Prime number generation
MehediHasan1134
 
THE NUMBER SYSTEM
THE NUMBER SYSTEMTHE NUMBER SYSTEM
THE NUMBER SYSTEM
SrushtiShetty1
 
Year 10 Mathematics British outline.pptx
Year 10 Mathematics British outline.pptxYear 10 Mathematics British outline.pptx
Year 10 Mathematics British outline.pptx
victoriabodunde01
 
Number and operations review1
Number and operations review1Number and operations review1
Number and operations review1
Institute of Applied Technology
 
Nombor nyata kuliah 1 &amp; 2
Nombor nyata kuliah 1 &amp; 2Nombor nyata kuliah 1 &amp; 2
Nombor nyata kuliah 1 &amp; 2
nooriza kassim
 

Similar to Prime Number (Sieve) (14)

Presentation on Prime Numbers and Composite Numbers
Presentation on Prime Numbers and Composite NumbersPresentation on Prime Numbers and Composite Numbers
Presentation on Prime Numbers and Composite Numbers
 
Intengers!.pptx
Intengers!.pptxIntengers!.pptx
Intengers!.pptx
 
1672631 634959625708535000
1672631 6349596257085350001672631 634959625708535000
1672631 634959625708535000
 
BInary Number Representation
 BInary Number Representation BInary Number Representation
BInary Number Representation
 
Numeral System
Numeral SystemNumeral System
Numeral System
 
Power point presentation {nazareth}
Power point presentation {nazareth}Power point presentation {nazareth}
Power point presentation {nazareth}
 
Real basic define arivu
Real basic define arivuReal basic define arivu
Real basic define arivu
 
om kamthe power.pptx
om kamthe power.pptxom kamthe power.pptx
om kamthe power.pptx
 
MATHEMATICS 2
MATHEMATICS 2MATHEMATICS 2
MATHEMATICS 2
 
Prime number generation
Prime number generationPrime number generation
Prime number generation
 
THE NUMBER SYSTEM
THE NUMBER SYSTEMTHE NUMBER SYSTEM
THE NUMBER SYSTEM
 
Year 10 Mathematics British outline.pptx
Year 10 Mathematics British outline.pptxYear 10 Mathematics British outline.pptx
Year 10 Mathematics British outline.pptx
 
Number and operations review1
Number and operations review1Number and operations review1
Number and operations review1
 
Nombor nyata kuliah 1 &amp; 2
Nombor nyata kuliah 1 &amp; 2Nombor nyata kuliah 1 &amp; 2
Nombor nyata kuliah 1 &amp; 2
 

More from Al-Mamun Riyadh (Mun)

Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)
Al-Mamun Riyadh (Mun)
 
Workshop on arduino (ewurc)
Workshop on arduino (ewurc)Workshop on arduino (ewurc)
Workshop on arduino (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 4 python string (ewurc)
Lecture 4 python string (ewurc)Lecture 4 python string (ewurc)
Lecture 4 python string (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)
Al-Mamun Riyadh (Mun)
 
Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)
Al-Mamun Riyadh (Mun)
 

More from Al-Mamun Riyadh (Mun) (8)

Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)Lecture 1 python arithmetic (ewurc)
Lecture 1 python arithmetic (ewurc)
 
Workshop on arduino (ewurc)
Workshop on arduino (ewurc)Workshop on arduino (ewurc)
Workshop on arduino (ewurc)
 
Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)Lecture 6 python oop (ewurc)
Lecture 6 python oop (ewurc)
 
Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)Lecture 5 python function (ewurc)
Lecture 5 python function (ewurc)
 
Lecture 4 python string (ewurc)
Lecture 4 python string (ewurc)Lecture 4 python string (ewurc)
Lecture 4 python string (ewurc)
 
Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)Lecture 3.1 python loop 1 (ewurc)
Lecture 3.1 python loop 1 (ewurc)
 
Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)Lecture 2 python conditional (ewurc)
Lecture 2 python conditional (ewurc)
 
Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)Lecture 0 python basic (ewurc)
Lecture 0 python basic (ewurc)
 

Recently uploaded

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

Prime Number (Sieve)

  • 1.
  • 3. 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).
  • 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 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.
  • 6. 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
  • 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

Editor's Notes

  1. Good Morning Everyone. I welcome you all to my presentation on Prime Number.
  2. I am Md. Al-Mamun Riyadh. Let’s introduce with Prime Number.
  3. 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.
  4. 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.
  5. 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.
  6. 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
  7. 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))
  8. 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.
  9. thank you, everyone, for joining me in this presentation. you may ask your query if any, please.