Given a series of numbers 0  1  4  18  96  600  4320 …., and series starting from zeroth term. Given n, find the nth value of the series.
 
Example 1:
Input: n = 4
Output: 96
Example 2:
Input: n = 2
Output: 4
 
Your Task:
You don't need to read or print anything, Your task is to complete the function NthTerm() which takes n as input parameter and returns the nth value of the given series modulo 10^{9} + 7.
 
Expected Time Complexity: O(n)
Expected Space Complexity: O(1)
Constraints:
1 <= n <= 10000

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Combinatorics

Starter code: #User function Template for python3

class Solution:
	def NthTerm(self, n):
		# Code here

Solutions:
class Solution:

	def solve(self, n):
		ans = 1
		for i in range(1, n + 1):
			ans = ans * i
		return ans

	def NthTerm(self, n):
		a = self.solve(n)
		return n * a % (10 ** 9 + 7)


class Solution:

	def NthTerm(self, n):
		mod = pow(10, 9) + 7
		product = 1
		for i in range(1, n + 1):
			product = product * i
		answer = product * n
		answer = answer % mod
		return answer


class Solution:

	def NthTerm(self, n):
		if n == 0:
			return 0
		p = 1
		for i in range(1, n + 1):
			p = p * i
			p = p % 1000000007
		p = p * n
		return p % 1000000007


class Solution:

	def NthTerm(self, n):
		mod = 10 ** 9 + 7
		if n == 0:
			return 0
		if n == 1:
			return 1
		c = 1
		f = 1
		for i in range(1, n):
			c *= f
			f += 1
		return n * n % mod * c % mod


from math import factorial

class Solution:

	def NthTerm(self, n):
		return n * factorial(n) % (10 ** 9 + 7)


class Solution:

	def NthTerm(self, n):
		factorial = 1
		for i in range(1, n):
			factorial *= i
		return n * n * factorial % 1000000007


import math

class Solution:

	def NthTerm(self, n):
		return n * math.factorial(n) % 1000000007


import math

class Solution:

	def NthTerm(self, n):
		if n == 0:
			return 0
		else:
			return n * n * math.factorial(n - 1) % 1000000007


class Solution:

	def NthTerm(self, n):
		num = 1
		for i in range(2, n):
			num *= i
		num *= n * n
		x = num % (10 ** 9 + 7)
		return x


def solve(n):
	p = 1
	while n:
		p = p * n
		n -= 1
	return p

class Solution:

	def NthTerm(self, n):
		x = solve(n) * n
		return x % (10 ** 9 + 7)


def fact(n):
	f = 1
	for i in range(1, n + 1):
		f *= i
	return f

class Solution:

	def NthTerm(self, n):
		return n * fact(n) % (10 ** 9 + 7)