{"id":"fd9e2ff1-a0ea-475d-b5ad-b4e7bdc814b8","name":"Sieve Of Eratosthenes","description":"1. Given an Integer 'n'.\r\n2. Print all primes from 2 to 'n'.\r\n3. Portal is not forced you, but try to submit the problem in less than n.root(n) complexity.\r\n","inputFormat":"n = 10\r\n","outputFormat":"2 3 5 7","constraints":"2 &lt;= n &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvoid printPrimeUsingSieve(int n){\n //Write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n printPrimeUsingSieve(n);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n \r\n // ~~~~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~~\r\n public static void printPrimeUsingSieve(int n) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~\r\n public static void main(String[] args) { \r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n printPrimeUsingSieve(n);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10","sampleOutput":"2 3 5 7 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"7838f824-61ab-44dd-a86a-5303e999cb49","name":"Sieve Of Eratosthenes","slug":"sieve-of-eratosthenes","type":1}],"next":{"id":"7b1a6f3a-db56-486a-8d67-fe530948e90d","name":"Sieve Of Eratosthenes","type":3,"slug":"sieve-of-eratosthenes"},"prev":{"id":"2a6ab17a-030d-48cf-a143-5e5486aa83fb","name":"Car Fleet MCQ","type":0,"slug":"car-fleet-mcq"}}}

Sieve Of Eratosthenes

1. Given an Integer 'n'. 2. Print all primes from 2 to 'n'. 3. Portal is not forced you, but try to submit the problem in less than n.root(n) complexity.

{"id":"fd9e2ff1-a0ea-475d-b5ad-b4e7bdc814b8","name":"Sieve Of Eratosthenes","description":"1. Given an Integer 'n'.\r\n2. Print all primes from 2 to 'n'.\r\n3. Portal is not forced you, but try to submit the problem in less than n.root(n) complexity.\r\n","inputFormat":"n = 10\r\n","outputFormat":"2 3 5 7","constraints":"2 &lt;= n &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvoid printPrimeUsingSieve(int n){\n //Write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n printPrimeUsingSieve(n);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n \r\n // ~~~~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~~\r\n public static void printPrimeUsingSieve(int n) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~\r\n public static void main(String[] args) { \r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n printPrimeUsingSieve(n);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10","sampleOutput":"2 3 5 7 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"7838f824-61ab-44dd-a86a-5303e999cb49","name":"Sieve Of Eratosthenes","slug":"sieve-of-eratosthenes","type":1}],"next":{"id":"7b1a6f3a-db56-486a-8d67-fe530948e90d","name":"Sieve Of Eratosthenes","type":3,"slug":"sieve-of-eratosthenes"},"prev":{"id":"2a6ab17a-030d-48cf-a143-5e5486aa83fb","name":"Car Fleet MCQ","type":0,"slug":"car-fleet-mcq"}}}
plane

Editor


Loading...

Sieve Of Eratosthenes

easy

1. Given an Integer 'n'. 2. Print all primes from 2 to 'n'. 3. Portal is not forced you, but try to submit the problem in less than n.root(n) complexity.

Constraints

2 <= n <= 10^5

Format

Input

n = 10

Output

2 3 5 7

Example

Sample Input

10

Sample Output

2 3 5 7

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode