PRIMEN - Sieve of Eratosthenes

no tags 

Heard of a procedure called sieve of Eratosthenes? Well, implement this:

  1. Fill an array num[n] (where 0 <= n <= 1000) with numbers from 1 to n.
  2. Starting with the second entry in the array, set all its multiples to zero.
  3. Proceed to the next non-zero element and set all its multiples to zero.
  4. Repeat step 3 until you have set up the multiples of all the non-zero elements to zero.
  5. At the conclusion of step 4, all the non-zero entries left in the array would be ... (obviously) prime numbers, so print out these numbers.

Input

First line consists of number of test cases t (0 <= t <= 100). The next lines refers to the values of n (0 <= n <= 1000).

Output

The prime numbers up to n with output of each test case separated by an extra line.

Example

Input:
2
5
10

Output:
1
2
3
5

1
2
3
5
7

hide comments
shahwat: 2018-05-25 14:34:51

Can anyone explain the verdict '100'? I think it represents Accepted. If it is, wii you change it to that verdict. So that, people won't get confused. :)

mir_lutfur: 2016-02-11 18:56:32

what is the meaning of verdict 100?


Added by:kousik
Date:2013-09-13
Time limit:1s-5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYTHON PYPY PYPY3 PYTHON3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET