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

#SP0000064. Sàng Sundaram (Sieve of Sundaram)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Sàng Sundaram (Sieve of Sundaram)

Sieve of Sundaram

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given integer nn, list all primes not greater than nn in increasing order. The original problem requires the Sieve of Sundaram: consider indices 1,2,…,⌊(n−1)/2⌋1,2,\ldots,\lfloor(n-1)/2\rfloor and remove every index expressible as i+j+2iji+j+2ij with 1≤i≤j1\le i\le j; each remaining index kk produces an odd prime 2k+12k+1. Handle prime 22 separately.

Input

One line contains integer nn.

Output

Print all primes not greater than nn on one line, in ascending order, separated by a single space.

Subtasks

  • Subtask 1 (20 points): 2≤n≤1002\le n\le 100.
  • Subtask 2 (30 points): 2≤n≤100002\le n\le 10000.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000.

Examples

Input

7

Output

2 3 5 7

Explanation

For n=7n=7, consider indices 1,2,31,2,3. The smallest removal index is 1+1+2(1)(1)=41+1+2(1)(1)=4, beyond the limit 33; none is removed. Add prime 22 separately and convert k=1,2,3k=1,2,3 into 3,5,73,5,7. Print 2 3 5 7.