luogu#P2391. 白雪皑皑

白雪皑皑

Background

"By the brushwood gate, a dog barks; through wind and snow, a traveler returns at night." Winter arrives unexpectedly. A thousand miles are frozen, and ten thousand miles are swept by snow. Feathery snow whirls in the air, and snowflakes drift down to the world. The people on the Planet of Positive Energy (a colony of pty on spore) are awed by this beauty. However, pty is not pleased; he dislikes a world of white and finds it too monotonous. So he wants to dye the snowflakes to make the world more colorful.

Problem Description

There are nn snowflakes arranged in a line. pty will perform mm coloring operations. In the ii-th coloring operation, he colors all snowflakes between the ((i×p+q)modn)+1((i\times p+q)\bmod n)+1-th snowflake and the ((i×q+p)modn)+1((i\times q+p)\bmod n)+1-th snowflake (inclusive) with color ii. Here p,qp, q are two given positive integers. He wants to know the final color of each of the nn snowflakes. Output 00 for any snowflake that is never colored.

Input Format

The input consists of four lines, each containing one integer, namely n,m,p,qn, m, p, q, as described above.

Output Format

Output nn lines. The ii-th line contains one integer, the color of the ii-th snowflake.

4
3
2
4
2
2
3
0

Hint

  • For 20%20\% of the testdata: n,m1000n,m\leq 1000.
  • For 40%40\% of the testdata: n8000n\leq 8000, m106m\leq 10^6.
  • For 80%80\% of the testdata: n5×105n\leq 5\times 10^5, m107m\leq 10^7.
  • For 100%100\% of the testdata: 1n1061\leq n\leq 10^6, 1m1071\leq m\leq 10^7.

It is guaranteed that 1m×p+q,m×q+p2×1091\leq m\times p+q,m\times q+p\leq 2\times 10^9.

Translated by ChatGPT 5