Count of numbers upto M divisible by given Prime Numbers | Function to count the numbers that are divisible by the numbers in the array from range 1 to M ; Initialize the count variable ; Iterate over [ 1 , M ] ; Iterate over array elements arr [ ] ; Check if i is divisible by a [ j ] ; Increment the count ; Return the answer ; Given array arr [ ] ; Given Number M ; Function Call
function count ( a , M , N ) { let cnt = 0 ; for ( let i = 1 ; i <= M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( i % a [ j ] == 0 ) { cnt ++ ; break ; } } } return cnt ; } let arr = [ 2 , 3 , 5 , 7 ] ; let m = 100 ; let n = arr . length ; document . write ( count ( arr , m , n ) ) ;