Four mathematicians are invited to a remote house by an unknown host to solve a series of puzzles and riddles. When they arrive, the host reveals himself as "Fermat" and says they must solve the puzzles within time limits or the house will kill them. They work together to solve logic puzzles involving numbers and sequences. As they solve each puzzle, a flashback reveals more about the host's mysterious motivation for killing them if they fail.