PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000100. Liệt kê số nguyên tố trên khoảng (Prime Intervals)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Liệt kê số nguyên tố trên khoảng (Prime Intervals)

Prime Intervals

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers LL and UU, list all prime numbers in the closed interval [L,U][L,U], including both endpoints. A prime is an integer greater than 11 with exactly two distinct positive divisors. Output the primes in increasing order, one per line. If there are no primes in the interval, output nothing.

A prime equal to the left or right endpoint must also be printed because both endpoints are included.

Input

One line contains two integers LL and UU, the inclusive left and right endpoints of the interval.

Output

Print each prime in increasing order on its own line. If none exist, print nothing.

Subtasks

  • Subtask 1 (20 points): 2≤L<U≤100002\le L< U\le 10000; U−L≤500U-L\le 500.
  • Subtask 2 (30 points): 2≤L<U≤100000002\le L< U\le 10000000; U−L≤100000U-L\le 100000.
  • Subtask 3 (50 points): 2≤L<U≤21474836472\le L< U\le 2147483647; U−L≤1000000U-L\le 1000000.

Examples

Input

2 10

Output

2
3
5
7

Explanation

In [2,10][2,10], the numbers 2,3,5,72,3,5,7 are prime, whereas 4,6,8,9,104,6,8,9,10 are composite. Print 22, 33, 55, and 77 on separate lines.