Given two integers n and k, The task is to calculate Permutation Coefficient P(n,k)
Note: P(n, k) is used to represent the number of ways to obtain an ordered subset having k elements from a set of n elements.Since this value may be large only find it modulo 10^9 + 7.
Example 1:
Input: n = 10, k = 2
Output: 90
Explanation: For first case:
Ans = 10! / (10 - 2)! = 10! / 8!
10! is 8!*9*10 and 8! is 8!
Ans = 9*10 = 90
Example 2:
Input: n = 10, k = 3
Output: 720
Your Task:
You don't need to read or print anything. Your task is to complete the function permutationCoeff() which takes integers n and kas input parameters and returns an integer.
Expected Time Complexity: O(n)
Expected Space Complexity: O(1)
 
Constraints:
1 ≤ k ≤ n ≤ 100000

Source: geeksforgeeks | Difficulty: MEDIUM

Starter code: #User function Template for python3





class Solution:

	def permutationCoeff(self,n, k):

		# Code here

Solutions:
class Solution:

	def permutationCoeff(self, n, k):
		count1 = 1
		for i in range(n, n - k, -1):
			count1 = count1 * i
		return count1 % int(1000000000.0 + 7)


class Solution:

	def permutationCoeff(self, n, k):
		x = n - k
		factn = 1
		while n > x:
			factn = factn * n
			n -= 1
			if n == x:
				break
		return factn % (10 ** 9 + 7)


class Solution:

	def permutationCoeff(self, n, k):
		if k == 1:
			return n
		pro = 1
		for i in range(0, k):
			pro = pro * n
			pro = pro % (10 ** 9 + 7)
			n -= 1
		pro = pro % (10 ** 9 + 7)
		return pro


from math import factorial

class Solution:

	def permutationCoeff(self, n, k):
		return factorial(n) // factorial(n - k) % (10 ** 9 + 7)


class Solution:

	def permutationCoeff(self, n, k):
		t = n - k
		s = n - t
		fact = 1
		for i in range(s):
			fact = fact * n
			n = n - 1
		return fact % (10 ** 9 + 7)


import math

class Solution:

	def permutationCoeff(self, n, k):
		a = math.factorial(n)
		b = math.factorial(n - k)
		c = a // b
		return c % (10 ** 9 + 7)


import math

class Solution:

	def permutationCoeff(self, n, k):
		new = 1
		for i in range(n - k + 1, n + 1):
			new *= i
		return new % 1000000007


from math import factorial

class Solution:

	def permutationCoeff(self, n, k):
		p = 1
		for i in range(n, n - k, -1):
			p *= i
		return p % (10 ** 9 + 7)


class Solution:

	def permutationCoeff(self, n, k):
		m = 1000000007
		p = 1
		for i in range(n, n - k, -1):
			p = p * i
		return p % m


class Solution:

	def permutationCoeff(self, n, k):
		res = 1
		for i in range(n, n - k, -1):
			res *= i
		return res % (10 ** 9 + 7)


class Solution:

	def permutationCoeff(self, n, k):
		mod = 10 ** 9 + 7
		r = 1
		for i in range(n, n - k, -1):
			r = r * i % mod
		return r


P = 10 ** 9 + 7

class Solution:

	def permutationCoeff(self, n, k):
		ans = 1
		for i in range(n - k + 1, n + 1):
			ans = ans * i % P
		return ans


import sys
MOD = 10 ** 9 + 7

class Solution:

	def permutationCoeff(self, n, k):
		f = 1
		for i in range(k):
			f *= n - i
			f = f % MOD
		return f


import math

class Solution:

	def permutationCoeff(self, n, k):
		N = math.factorial(n)
		r = math.factorial(n - k)
		val = N // r
		return val % 1000000007


class Solution:

	def permutationCoeff(self, n, k):
		ans = 1
		m = 10 ** 9 + 7
		while k > 0:
			ans *= n
			n = n - 1
			ans %= m
			k = k - 1
		return ans


class Solution:

	def permutationCoeff(self, n, k):
		fact = 1
		while k > 0:
			fact *= n
			n -= 1
			k -= 1
		return fact % (10 ** 9 + 7)