Every pseudo-random generator is a hidden state updated by a fixed rule. Build the simplest one.
What to build
A program that prints the first n numbers of a linear congruential generator.
Requirements
- Starting from x = seed, repeat n times: x = (a·x + c) mod m, then output x.
- Print the n numbers on one line, separated by spaces.
Input
One line: seed, a, c, m and n.
Output
One line.
Constraints
0 ≤ seed, a, c < m ≤ 2³²; 1 ≤ n ≤ 1000.
Example
Input:
1 5 3 16 6
Output:
8 11 10 5 12 15
Why it works
The rule is deterministic, so the same seed always produces the same sequence, which is exactly what makes seeded simulations reproducible.
Examples
Example 1 · Input
1 5 3 16 6
Expected output
8 11 10 5 12 15
Example 2 · Input
0 1 1 10 4
Expected output
1 2 3 4
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Update the state with x = (a * x + c) % m and print each new x.
Hint 2
The seed itself is not printed.
Solution
Show one correct solution (try it yourself first)
seed, a, c, m, n = map(int, input().split())
x = seed
out = []
for _ in range(n):
x = (a * x + c) % m
out.append(x)
print(" ".join(map(str, out)))