Question Link import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { static class SinglyLinkedListNode { public int data; public SinglyLinkedListNode next; public SinglyLinkedListNode(int nodeData) { this.data = nodeData; this.next = null; } } static class SinglyLinkedList { public SinglyLinkedListNode head; public SinglyLinkedListNode tail; public SinglyLinkedList() { ...
Sieve of Eratosthenis Algorithm:- 1. Create a list of consecutive integers from 2 to n: (2, 3, 4, …, n). 2. Initially, let p equal 2, the first prime number. 3. Starting from p2, count up in increments of p and mark each of these numbers greater than or equal to p2 itself in the list. These numbers will be p(p+1), p(p+2), p(p+3), etc.. 4. Find the first number greater than p in the list that is not marked. If there was no such number, stop. Otherwise, let p now equal this number (which is the next prime), and repeat from step 3. <--> When the algorithm terminates, all the numbers in the list that are not marked false are prime. If you want the code for it then comment down.
Comments
Post a Comment