Given a number n , count all multiples of 3 and / or 5 in set { 1 , 2 , 3 , ... n } | PHP 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
< ? php function countOfMultiples ( $ n ) { return floor ( floor ( $ n / 3 ) + floor ( $ n / 5 ) - floor ( $ n / 15 ) ) ; } echo countOfMultiples ( 6 ) , " STRNEWLINE " ; echo countOfMultiples ( 16 ) ; ? >