The total possible 4 digit numbers are 9×10×10×10=9000
Let, X is the 4 digit number divisible by 3
1002,1005,………,9999
a=1002,d=3&{a}_{n}=9999
9999=1002+(n3−1)3
n3=3000
Let, Y is the 4 digit numbers divisible by 7
1001,1008,………,9996
a=1001,d=7&{a}_{n}=9996
9996=1001+(n7−1)7
n7=1286
Now, 4 digit numbers divisible by both 3 and 7
1008,1029,...........9996
a=1008,d=21,an=9996
Now, 9996=1008+(n−1)21
n=429
Hence, 4 digit numbers neither divisible by 7 nor 3
=9000−1286−3000+429
=5143