blob: fe221ffda9f5181092018df7769da4719fc1bafe (
plain)
1
2
3
4
5
6
7
8
9
10
11
|
U=1000; //number of elements in the set of positive integers not exceeding 1000
A=U/3; //number of elements in the subset of integers divisible by 3
B=U/5; //number of elements in the subset of integers divisible by 5
C=U/7; //number of elements in the subset of integers divisible by 7
AandB=floor(U/(3*5)) //number of elements in the subset containing numbers divisible by both 3 and 5
AandC=floor(U/(3*7)) //number of elements in the subset containing numbers divisible by both 3 and 7
BandC=floor(U/(5*7)) //number of elements in the subset containing numbers divisible by both 5 and 7
AandBandC=floor(U/(3*5*7)) //number of elements in the subset containing numbers divisible by 3,5 and 7
s=U-(A+B+C)+(AandB+AandC+BandC)-(AandBandC); // By inclusion-exclusion principle
S=round(s);
disp(S,'The number of integers in the set U, which are not divisible by 3,5 and 7 is')
|