scope # find the count of the divisors of the first 100 positive integers # returns the number of divisors of v local proc divisor_count( v :: number ) :: number # numtheory.ifactors will return something like (e.g., for 24): [1, [[2, 3], [3, 1]]] local total := 1; if v > 1 then local constant factors := numtheory.ifactors( v ); for f to size factors[ 2 ] do total *:= factors[ 2, f, 2 ] + 1 od fi; return total end; scope local constant limit := 100; printf( "Count of divisors for the first %d positive integers:\n", limit ); for n to limit do printf( "%3d", divisor_count( n ) ); if n mod 20 = 0 then print() else printf( " " ) fi od end end