401603: GYM100499 B K smallest numbers

Memory Limit:256 MB Time Limit:8 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. K smallest numberstime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Given an array A of N integers A1, A2, A3, ..., AN. This array is generated by the following formula:

A1 = S

Ai = (C1 * Ai - 1 + C2) mod M, for i = 2..N

Your task is very simple. Find out K smallest integers among the N generated integers.

Input

First line of input consist number of test case T (T ≤ 20). Each of the next T lines describe a test case. Each test case consists of six numbers: N, K, S, C1, C2, M where:

  • 1 ≤ N ≤ 107
  • K ≤ min(N, 100)
  • 0 ≤ S, C1, C2 ≤ 107
  • 2 ≤ M ≤ 107
Output

For the ith test case, you should print K smallest numbers in ascending order on the ith line of output. The numbers should be seperated by a single space.

ExamplesInput
2
10000 9 71 197 5 91723
2014 4 27 279 64 97264
Output
3 4 4 24 40 40 41 49 71 
27 77 221 251

加入题单

算法标签: