Inclusion and Exclusion Theorem

 
 

Given a number n, find how many numbers from 1 to n are not multiples of 2 3 5 7:

First, find out how many are multiples of 2, 3, 5, and 7, and suppose there are a, b, c, and d respectively. 
Then find out how many are 6 (the least common multiple of 2 and 3), 10 (the least common multiple of 2 and 5), 14 (the least common multiple of 2 and 7), 15 (the least common multiple of 3 and 5), and 21 (the least common multiple of 3 and 7) , 35 (5 and 7) multiples of the least common multiple, and there are e, f, g, h, i, and j respectively.
Then find out how many are 30 (2, 3, 5 least common multiple), 42 (2, 3, 7 least common multiple), 70 (2, 5, 7 least common multiple), 105 (3, 5, 7 least common multiple) The multiples are assumed to be k, l, m, and n respectively.
Then find how many are multiples of 210 (2, 3, 5, 7 least common multiple), there are 0, and
finally, the numbers that are not multiples of 2, 3, 5, 7 are:
[n-(a+b+c +d)+(e+f+g+h+i+j)-(k+l+m+n)+o]


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325369147&siteId=291194637