If Michael takes M weeks to build a house by himself and Thomas takes T weeks, then we can say that if they build a house together in 6 weeks, in one week they can build 1/6 of a house. By himself in a week, Michael can build 1/M of a house and by himself Thomas can build 1/T of a house, so working together: 1/M+1/T=1/6; multiplying through by 6MT: 6T+6M=MT; MT-6T=6M. Also M=T-5, because Michael takes 5 fewer weeks than Thomas to build a house.
Substituting for M we have: T^2-5T-6T=6T-30; T^2-17T+30=0; (T-15)(T-2)=0, T=15 or 2. M=T-5, so M=10 or -3. We can reject -3 as being meaningless, so M=10 weeks.
Check: 1/M+1/T=1/10+1/15=3/30+2/30=5/30=1/6. They can build a house together in 6 weeks.