Explanation
Let's denote the total number of books as x.
Hadith books = 2/5 × x = 2x/5
Remaining books = x - 2x/5 = 3x/5
Mathematics books = 3/4 × 3x/5 = 9x/20
Books on other subjects = 3x/5 - 9x/20
= (12x - 9x)/20
= 3x/20
Given that the number of books on other subjects is 642:
3x/20 = 642
x = 642 × 20/3
x = 4280