human
Total number of divisors for a given number | program for finding no . of divisors.
sieve method for prime calculation.
Traversing through all prime numbers.
calculate number of divisor with formula total div = ( p1 + 1 ) * ( p2 + 1 ) * ... . . * ( pn + 1 ) where n = ( a1 ^ p1 ) * ( a2 ^ p2 ) . ... * ( an ^ pn ) ai being prime divisor for n and pi are their respective power in factorization.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to total number of divisors for a given number and the other steps required.
 def divCount ( n ) :
	hh = [ 1 ] * ( n + 1 ) ;
	p = 2 ;
	while ( ( p * p ) < n ) :
		if ( hh [ p ] == 1 ) :
			for i in range ( ( p * 2 ) , n , p ) :
				hh [ i ] = 0 ;
		p += 1 ;
	total = 1 ;
	for p in range ( 2 , n + 1 ) :
		if ( hh [ p ] == 1 ) :
			count = 0 ;
			if ( n % p == 0 ) :
				while ( n % p == 0 ) :
					n = int ( n / p ) ;
					count += 1 ;
				total *= ( count + 1 ) ;
	return total ;
n = 24 ;
print ( divCount ( n ) ) ;