Benches (Codeforces 630H)
Tags: Math, combinatorics

The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.Help the park administration count the number of ways to place the benches.

Input: The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.

Output: Output one integer — the number of ways to place the benches.


Sample Inputs:
5

Sample Outputs:
120

Solution (Python):
def C(m, n):
    ans = 1
    num = 1
    while n > 0:
        ans *= m
        ans //= num
        m -= 1
        num += 1
        n -= 1
    return ans
n = int(input())
print(120 * C(n, 5) * C(n, 5))

Solution (Python):
factorials = [1] * 105
fact = 1
for i in range(1, 105):
    fact *= i
    factorials[i] = fact

def factorial(x):
    return factorials[x]

def comb(x, y):
    return factorial(x) // (factorial(y) * factorial(x - y))
x = int(input())
print(int(comb(x, 5)) * x * (x - 1) * (x - 2) * (x - 3) * (x - 4))

Solution (Python):
def solve():
    n = int(input())
    x = n * (n - 1) * (n - 2) * (n - 3) * (n - 4)
    result = x * x // 120
    print(result)
solve()