Pipeline cycle count

A pipeline fills once and then finishes one instruction per cycle. Compare it with a machine that runs one instruction at a time.

What to build

A program that prints the cycle counts with and without pipelining, and the speedup.

Requirements

  • Print pipelined C with C = k + n − 1 and unpipelined U with U = k × n.
  • Print speedup S with S = U ÷ C to 2 decimal places.

Input

One line: k (stages) and n (instructions).

Output

Three lines.

Constraints

1 ≤ k ≤ 30; 1 ≤ n ≤ 10⁶.

Example

Input:

5 100

Output:

pipelined 104
unpipelined 500
speedup 4.81

Why it works

The first instruction needs k cycles to pass through all stages, and every later one finishes one cycle after the one before it, which adds n − 1 cycles.

Examples

Example 1 · Input
5 100
Expected output
pipelined 104
unpipelined 500
speedup 4.81
Example 2 · Input
5 1
Expected output
pipelined 5
unpipelined 5
speedup 1.00

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Pipelined cycles = k + n - 1; unpipelined cycles = k * n.

Hint 2

The speedup is unpipelined ÷ pipelined; print it with f"{x:.2f}".

Solution

Show one correct solution (try it yourself first)
k, n = map(int, input().split())
c, u = k + n - 1, k * n
print("pipelined", c)
print("unpipelined", u)
print(f"speedup {u / c:.2f}")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Pipelining →