Under construction

Still being built. Things may change

Find Prime Numbers

Interview

Time limit2sMemory limit256 MB

Summary
Print all prime numbers between two given bounds M and N, one per line, using an efficient sieve up to 1,000,000.
Level

Easy3 of 10

Topics
Math, Number theory, Sorting
Solved
No attempts yet

Problem

Given two natural numbers M and N, write a program that prints every prime number from M through N in increasing order.

Input

The first line contains the natural numbers M and N separated by a space.

  • 1 ≤ M ≤ N ≤ 1,000,000
  • The input always contains at least one prime number in the inclusive range [M, N].

Output

Print the prime numbers from M through N in increasing order, one per line.

Examples1

  1. Example 1

    Input
    3 16
    
    Expected output
    3
    5
    7
    11
    13