First I count all the numbers of type 5xxx (where x can be a number between 0 and 9). There are 10*10*10=1000. Let this be A.
Then I add all the numbers of type y5xx (where y can be 1, 2, 3, 4, 5, 6, 7, 8, 9). There are 9*10*10=900. Let this be B.
Then I add all the numbers of type yz5x (where z can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9). There is 9*10*10. Let this be C.
Then I add all the numbers of type yzz5. There is 9*10*10=900. Let this be D.
So P(A)=1000;
P(B)=900;
P(C)=900;
P(D)=900;
P(A ∩ B)=100; //all numbers of type 55xx (where x can be a number between 0 and 9).
P(A ∩ C)=100; //all numbers of type 5x5x(where x can be a number between 0 and 9).
P(A ∩ D)=100; //all numbers of type 5xx5(where x can be a number between 0 and 9).
P(B ∩ C)= 90; //all numbers of type y55x(where x can be a number between 0 and 9 and y can be a number between 1 and 9).
P(B ∩ D)=90; //all numbers of type y5x5(where x can be a number between 0 and 9 and y can be a number between 1 and 9).
P(C ∩ D)=90; //all numbers of type yx55(where x can be a number between 0 and 9 and y can be a number between 1 and 9).
P(A ∩ B ∩ C)=10; //all numbers of type 555x(where x can be a number between 0 and 9).
P(A ∩ B ∩ D)=10; //all numbers of type 55x5(where x can be a number between 0 and 9).
P(A ∩ C ∩ D)=10; //all numbers of type 5x55(where x can be a number between 0 and 9).
P(B ∩ C ∩ D)=9; //all numbers of type y555(where y can be a number between 1 and 9).
P(A ∩ B ∩ C ∩ D)=1; // this is 5555
so
P (A U B U C U D ) = P (A ) + P (B ) + P (C ) + P (D ) - P (A ∩ B ) - P (A ∩ C ) - P( A ∩ D )- P (B ∩ C ) - P ( B ∩ D ) - P (C ∩ D ) + P (A ∩ B ∩ C ) + P (A ∩ B ∩ D ) + P (A ∩ C ∩ D ) + P (B ∩ C ∩ D ) - P ( A ∩ B ∩ C ∩ D )
which numerically is
P (A U B U C U D ) = 1000 + 900 + 900 + 900 - 100 - 100 - 100 - 90 - 90 - 90 + 10 + 10 + 10 + 9 - 1
=3168