40 teams is easy. 8 groups of 5 teams, there just an extra round of games in the group stage (every team plays 4 instead of 3), and then the rest of the tournament structure stays the same.
A 36 team comp could have 9 groups, winners and 7 best 2nd placed sides go through. Would only add 6 games to the tournament too