Find the number of divisors of all numbers in the range [ 1 , n ] | Function to find the number of divisors of all numbers in the range [ 1 , n ] ; Array to store the count of divisors ; For every number from 1 to n ; Increase divisors count for every number divisible by i ; Print the divisors ; Driver code
< ? php function findDivisors ( $ n ) { $ div = array_fill ( 0 , $ n + 2 , 0 ) ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { for ( $ j = 1 ; $ j * $ i <= $ n ; $ j ++ ) $ div [ $ i * $ j ] ++ ; } for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) echo $ div [ $ i ] , " ▁ " ; } $ n = 10 ; findDivisors ( $ n ) ; ? >