{"id":9523,"date":"2021-10-01T10:30:40","date_gmt":"2021-10-01T05:00:40","guid":{"rendered":"https:\/\/python-programs.com\/?p=9523"},"modified":"2021-11-22T18:33:28","modified_gmt":"2021-11-22T13:03:28","slug":"python-program-to-read-print-prime-numbers-in-a-range-using-sieve-of-eratosthenes","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-read-print-prime-numbers-in-a-range-using-sieve-of-eratosthenes\/","title":{"rendered":"Python Program to Read Print Prime Numbers in a Range using Sieve of Eratosthenes"},"content":{"rendered":"

The Sieve of Eratosthenes is a very old and conventional algorithm for finding all prime numbers that are less or equal to a given number. If the number is less than or equal to 10 million or so, the Eratosthenes sieve is highly effective. You may get a thorough explanation of the algorithm on Wikipedia.<\/p>\n

Given the lower limit and upper limit the task is to print prime numbers in the given range using sieve of Eratosthenes in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Enter some random upper limit range = 529<\/pre>\n

Output:<\/strong><\/p>\n

The prime numbers from 1 to 529 are :\r\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 \r\n149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281\r\n283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443\r\n449 457 461 463 467 479 487 491 499 503 509 521 523<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Enter some random upper limit range = 129<\/pre>\n

Output:<\/strong><\/p>\n

The prime numbers from 1 to 129 are :\r\n2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127<\/pre>\n

Program to Read Print Prime Numbers in a Range using Sieve of Eratosthenes<\/h2>\n