With the last example, instead of 5 heats of 8 and 1 heat of 4, wouldn't you prefer
4 heats of 7 and 2 heats of 8
Algorithm is divide number of contestants (C) by 8, round up to next whole number (N). Remainder (R) is N*8 - C
Have R heats of 7 and (N-R) heats of 8