Given a number n , count all multiples of 3 and / or 5 in set { 1 , 2 , 3 , ... n } | C # 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 program to test above function
using System ; public class GFG { static uint countOfMultiples ( uint n ) { return ( n / 3 + n / 5 - n / 15 ) ; } static public void Main ( ) { Console . WriteLine ( countOfMultiples ( 6 ) ) ; Console . WriteLine ( countOfMultiples ( 16 ) ) ; } }