Given a number N, count total number of divisors of N!.
Example 1:
Input : N = 4
Output: 8
Explaination: 4! is 24. Divisors of 24 are 
1, 2, 3, 4, 6, 8, 12 and 24.
Example 2:
Input : N = 5
Output : 16
Explaination: 5! is 120. Divisors of 120 are 
1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24 30, 
40, 60 and 120.
Your Task:
You do not need to read input or print anything. Your task is to complete the function totalDivisors() which takes N as input parameter and returns total number of divisors of N!.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 100

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Number theory

Mathematics

Starter code: #User function Template for python3

class Solution:
    def totalDivisors(self, N):
        # code here

Solutions:
import math as m

class Solution:

	def totalDivisors(self, N):
		primes = [True] * (N + 1)
		prime_factors = []
		for i in range(2, N + 1):
			if primes[i]:
				j = i * i
				while j <= N:
					primes[j] = False
					j += i
				k = i
				count = 0
				while k <= N:
					count += N // k
					k *= i
				prime_factors.append(count)
		total_divisors = 1
		for count in prime_factors:
			total_divisors *= count + 1
		return total_divisors


class Solution:

	def totalDivisors(self, n):
		from collections import Counter
		rec = Counter()
		for i in range(2, n + 1):
			div = 2
			while i > 1:
				if i % div == 0:
					i //= div
					rec[div] += 1
				else:
					div += 1
		ans = 1
		for x in rec.values():
			ans *= x + 1
		return ans


class Solution:

	def totalDivisors(self, n):

		def find_Prime(n):
			ans = [2]
			prime = [1 for i in range(n + 1)]
			i = 3
			while i * i <= n:
				if prime[i]:
					for j in range(3 * i, n + 1, 2 * i):
						prime[j] = 0
				i += 2
			for i in range(3, n + 1, 2):
				if prime[i]:
					ans.append(i)
			return ans
		prime = find_Prime(n)
		ans = 1
		for i in prime:
			k = i
			a = 0
			while n // k:
				a += n // k
				k *= i
			ans *= a + 1
		return ans


class Solution:

	def solve(self, n):
		s = 1
		c = 2
		d = {}
		while n > 1:
			if n % c == 0:
				d[c] = d.get(c, 0) + 1
				n = n // c
			else:
				c += 1
		for i in d.keys():
			s = s * (d[i] + 1)
		return s

	def fact(self, n):
		if n == 0 or n == 1:
			return 1
		else:
			return n * self.fact(n - 1)

	def totalDivisors(self, N):
		a = self.fact(N)
		return self.solve(a)


class Solution:

	def totalDivisors(self, N):
		fact = 1

		def pf(n):
			i = 2
			s = 1
			while i * i <= n:
				if n % i == 0:
					t = 0
					while n % i == 0:
						t += 1
						n = n // i
					s = s * (t + 1)
				i += 1
			if n != 1:
				s = s * 2
			return s
		while N != 0:
			fact = fact * N
			N -= 1
		n = fact
		res = pf(n)
		return res


class Solution:

	def totalDivisors(self, n):
		l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
		i = 0
		m = []
		prod = 1
		while 1:
			k = n
			count = 0
			while k > 0:
				count = count + k // l[i]
				k = k // l[i]
			if count != 0:
				m.append(count)
			i = i + 1
			if i == 25:
				break
		for i in m:
			prod = prod * (i + 1)
		return prod


class Solution:

	def totalDivisors(self, num):
		arr = [i for i in range(1, num + 1)]
		mp = {}
		for i in range(num):
			j = 2
			while j * j <= arr[i] and arr[i] > 1:
				cnt = 0
				while arr[i] % j == 0:
					arr[i] = arr[i] // j
					cnt += 1
				if mp.__contains__(j):
					mp[j] += cnt
				else:
					mp[j] = cnt
				j += 1
			if arr[i] > 1:
				if mp.__contains__(arr[i]):
					mp[arr[i]] += 1
				else:
					mp[arr[i]] = 1
		ans = 1
		for k in mp:
			ans *= mp[k] + 1
		return ans