Given a number n , count all multiples of 3 and / or 5 in set { 1 , 2 , 3 , ... n } | Javascript program to find count of multiples of 3 and 5 in { 1 , 2 , 3 , . . n } ; Add multiples of 3 and 5. Since common multiples are counted twice in n / 3 + n / 15 , subtract common multiples ; Driver Code
function countOfMultiples ( n ) { return ( parseInt ( n / 3 , 10 ) + parseInt ( n / 5 , 10 ) - parseInt ( n / 15 , 10 ) ) ; } document . write ( countOfMultiples ( 6 ) + " " ) ; document . write ( countOfMultiples ( 16 ) + " " ) ;