Count of numbers upto M divisible by given Prime Numbers | C # program for the above approach ; 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 ; Driver code ; Given array [ ] arr ; Given number M ; Function call
using System ; class GFG { static int count ( int [ ] a , int M , int N ) { int cnt = 0 ; for ( int i = 1 ; i <= M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i % a [ j ] == 0 ) { cnt ++ ; break ; } } } return cnt ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 5 , 7 } ; int m = 100 ; int n = arr . Length ; Console . Write ( count ( arr , m , n ) ) ; } }