Count numbers in range 1 to N which are divisible by X but not by Y | Function to count total numbers divisible by x but not y in range 1 to N ; Check if Number is divisible by x but not Y if yes , Increment count ; Driver Code
< ? php function countNumbers ( $ X , $ Y , $ N ) { $ count = 0 ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) { if ( ( $ i % $ X == 0 ) && ( $ i % $ Y != 0 ) ) $ count ++ ; } return $ count ; } $ X = 2 ; $ Y = 3 ; $ N = 10 ; echo ( countNumbers ( $ X , $ Y , $ N ) ) ; ? >