A fraction p of a program can run in parallel on n cores; the rest is serial. Print the speedup from Amdahl's law, and the limit it approaches with unlimited cores.
Input
One line: p (a decimal from 0 to 1) and n (a whole number, 1 to 100000).
Output
Two lines: the speedup with 3 decimals, then limit and the limit with 3 decimals, or limit infinite when p is 1.
Examples
Example 1 · Input
0.8 10
Expected output
3.571 limit 5.000
Example 2 · Input
0.5 2
Expected output
1.333 limit 2.000
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
speedup = 1 / ((1 - p) + p / n).
Hint 2
With infinitely many cores, p / n becomes 0: the limit is 1 / (1 - p), unless p is 1.
Solution
Show one correct solution (try it yourself first)
p, n = input().split()
p, n = float(p), int(n)
print(f"{1 / ((1 - p) + p / n):.3f}")
print("limit infinite" if p == 1 else f"limit {1 / (1 - p):.3f}")