Base time limit: 1 seconds space limit: 131072 KB Score: 5 Difficulty: 1-level algorithm problem
Given a number n, ask 1 to N, how many are not multiples of 2 3 5 7. For example, n = 10, only 1 is not a multiple of 2 3 5 7.
Input
Enter 1 number n (1 <= n <= 10^18).
Output
The output is not the number of multiples of 2 3 5 7.
Input example
10
Output example
1
Said ashamed, thought of a night to finally figured out the principle of repulsion ... But fortunately finally figured out!
As the subject of the Four Yuan 2 3 5 7, by the test instructions can get {N/2}{N/3}{N/5}{N/7} four sets, then we can use the theorem to calculate the size of the four set merge set Num,n-num that is the request.
The calculation method of the combined set uses the tolerant theorem, that is, the total number of four sets minus 22 intersection number plus 33 The number of intersections and then minus 44 intersection number ....
The AC code is attached:
1#include <iostream>2 using namespacestd;3 4 intMain () {5 Long LongN;6Cin>>N;7 Long LongA,B,C,D,AB,AC,AD,BC,BD,CD,ABC,ABD,ACD,BCD,ABCD;8 Long Longnum=0;9a=n/2;Tenb=n/3; Onec=n/5; Ad=n/7; - -ab=n/6; theac=n/Ten; -ad=n/ -; -bc=n/ the; -bd=n/ +; +cd=n/ *; - +abc=n/ -; Aabd=n/ the; atbcd=n/ the; -acd=n/ -; - -abcd=n/ About; - -num=a+b+c+d-ab-ac-ad-bc-bd-cd+abc+abd+bcd+acd-ABCD; incout<<n-num<<Endl; - return 0; to}
Multiples of 2 3 5 7