For each question, print P(n, r), the number of ordered arrangements of r items out of n, and C(n, r), the number of unordered choices.
Input
The first line has t (1 ≤ t ≤ 20). Each of the next t lines has n and r (0 ≤ n, r ≤ 60).
Output
For each question, one line: P(n, r) and C(n, r), separated by a space. (When r > n, both are 0.)
Examples
Example 1 · Input
3 10 3 5 5 4 0
Expected output
720 120 120 1 1 1
Example 2 · Input
2 6 2 3 4
Expected output
30 15 0 0
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
P(n, r) = n! / (n − r)! and C(n, r) = P(n, r) / r!.
Hint 2
math.perm and math.comb exist, but try a loop: multiply n, n − 1, ... r times.
Hint 3
When r > n there are no ways: print 0 0.
Solution
Show one correct solution (try it yourself first)
t = int(input())
for _ in range(t):
n, r = map(int, input().split())
if r > n:
print(0, 0)
continue
p = 1
for k in range(n, n - r, -1):
p *= k
r_factorial = 1
for k in range(2, r + 1):
r_factorial *= k
print(p, p // r_factorial)