Find all divisors of first N natural numbers | Python3 program to find the factors of first N natural numbers ; Initialize divisor list ( array ) of sequence container ; Calculate all divisors of a number ; Function to find the factors of first n natural numbers ; Driver code ; Function call
MAX = 100001 NEW_LINE divisor = [ [ ] for x in range ( MAX ) ] NEW_LINE def sieve ( ) : NEW_LINE INDENT for i in range ( 1 , MAX ) : NEW_LINE INDENT for j in range ( i , MAX , i ) : NEW_LINE INDENT divisor [ j ] . append ( i ) NEW_LINE DEDENT DEDENT DEDENT def findNFactors ( n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( i , " ▁ - - > ▁ " , end = ' ' ) NEW_LINE for divi in divisor [ i ] : NEW_LINE INDENT print ( divi , " , ▁ " , end = ' ' ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE sieve ( ) NEW_LINE findNFactors ( n ) NEW_LINE DEDENT