The first assumption is that the worst case is the final answer. If the three socks are red, yellow and blue, then the socks to be drawn next will be bound into a pair with the socks drawn (set to red). At this time, there are still three situations, red, yellow and blue, but there is no guarantee that blue and Huang Dou will be painted, that is, assuming that red is painted again, so red is painted again. So the socks are all drawn, and now there is 12. It takes at least 13 to ensure two pairs of socks with different colors.
Second question, 40 books. 40-39= 1, the extra books will be given to students who have one book, ensuring that at least one student can get two books.