Reclusive high school math teacher Tetsuya Ishigami is "devoted" to two things: his math research and his neighbor, Yasuko Hanaoka. When Hanaoka and her daughter kill her abusive exhusband, they are shocked that Ishigami (a man they barely knew) comes to their rescue with an intricate plan to keep them safe from the police. The only thing he did not include in his plan was that the investigating detective happens to know Manubo Yukawa, a physicist who was Ishigami's only friend when they were university students together.
This book is a mystery in which the reader can piece together the clues, but unlike the traditional situation in which the puzzle is to determine the identity of the murderer, here the mystery is to figure out Ishigami's plan, and to see whether it will succeed. It becomes a battle of wits between Ishigami and Yukawa.
The mystery itself is not mathematical, but there is quite a bit of discussion of mathematics in the following ways:
 Ishigami is shown to be working on a proof of the Four Color Theorem, knowing fullwell that many mathematicians are satisfied with the proof provided by Appel and Haken, but is said to be seeking one that would appeal to Erdős. He lives in selfimposed isolation so that he can work on his mathematics without distraction, and does so because he loves mathematics, not because he seeks public recognition of his accomplishments.
 We see mathematics education in the interactions between Ishigami and his students. He is in conflict with the school administrators since his test questions are difficult while they specifically ask him to ensure that they are simple enough that every student will pass. Another point of interest is his answer to the eternal question "why do we need to learn this?".
 Yukawa, apparently testing whether his old friend's abilities have weakened as they both approach middle age, brings a purported counterexample to the Riemann Hypothesis to show Ishigami, and is suitably impressed when he is able to identify the flaw in only one night.
 A very interesting mathematical allusion arises in the occasional discussion of P vs. NP by Ishigami and Yukawa.
This famous open problem in mathematics has to do with how long it would take to solve certain problems as compared with merely checking a given proposed solution. In general, it is easier to check a potential answer than to find a real answer. [If we want to get even more specific, we have to introduce a number n which shows up in the statement of the question (it generally measures a size or complexity, like the number of digits in the "answer" or the size of the set being considered). We say a problem is in "P" if the amount of time it would take to check a possible answer for validity is less than some polynomial in n. Similarly, we say that a question is in "NP" if we actually can always find an answer to the question in an amount of time bounded by a polynomial in n. Theoretically, it seems possible for a question to be in P but not in NP, because solving it is so much harder than checking an answer.] But is it true? That is the question of P vs. NP.
There is an implicit analogy between this mathematical question and the situation in the story because Ishigami's scheme involves presenting a believable scenario to the police, an explanation for the murder that they will accept but does not implicate the Hanaokas. Yukawa's discussion of P vs. NP is like a coded message to Ishigami suggesting that the resolution of the plot depends upon whether the police will find their own solution before they give up trying to verify his proposed solution. However, I feel that the description in the book has the math backwards. It sounds as if he is implying that verifying a solution might be harder than finding a solution, and I do not think anyone seriously considers this a mathematical possibility. (As always, with books written in a language I cannot read, I have to consider that this misinterpretation of P vs. NP might have been introduced by the translator, since I have not read the book in its original Japanese.)
 Also important to the plot is the stereotype of the evil mathematician. For instance:
(quoted from The Devotion of Suspect X [Yôgisha X no kenshin])
"Maybe you're overthinking this. That guy might be a genius mathematician, but he's certainly a novice murderer."
"They're the same thing," Yukawa stated simply. "Murder probably comes even easier to him."

and
(quoted from The Devotion of Suspect X [Yôgisha X no kenshin])
"...[H]e's quite capable of committing an atrocity, provided that it's the logical course of action."

However, unlike other works I have tagged with the motif "evil mathematicians", it is not so clear how evil the reader will really think Ishigami is. It comes down to a question of what the honorable thing to do is in an ethically complicated situation (which certainly may be different in Japan), and also to what extent it is just a stereotype Ishigami is intentionally utilizing as part of his plan!
There is some discussion of academic life in the explanations of how both Ishigami and Yukawa end up in less impressive jobs than either would have thought from their stellar performances as students. Ishigami, perhaps unsurprisingly, does not deal well with the politics of academic life, and Yukawa's invention of magnetic gears did not work as well in practice as in theory. [BTW There is a famous physicist named Yukawa. Hideki Yukawa won a Nobel Prize for his work on elementary particles.]
This book was originally published in Japanese in 2005. When the translation appeared in 2011 it became the first major English language release by this author who already has had many best selling mysteries in his home country. It was also made into a movie in Japan in 2008. 