Concept:The correct preposition comes from the fixed expression "commit ... to memory".
Explanation:"Commit something to memory" means to memorize it exactly.
In this expression, the verb "commit" is always followed by the preposition "to".
The sentence means the teacher made us memorize the formula.
The other options, "on", "into", and "by", do not form this standard collocation.
Therefore, the best word to complete the sentence is "to".
Answer:B. to