A homeless man holds a man at knife point and asks for everything he has. He takes his money and watch and hits him in the head. As he walks through an alley he sees a shooting happen in an apartment. The shooter enters the alley and also shoots the homeless man.
Watson is at an old friend's grave. Joey, the friend's son, shows up. He offers to catch up with her over coffee.
Sherlock shows up at a crime scene uninvited. Bell says he doesn't need any help but since Sherlock is already there he allows him to stay. There is a body in the apartment, Felix, and one in the alley. The man in the alley had just committed a robbery. Bell says that a neighbor heard an argument the other day. Sherlock notices a smell and say that the room is covered in a special ink that is only visible when exposed to ultra violet light. He shines a black light and finds that the walls are covered in math equations and formulas. He thinks it's interesting but isn't sure it has anything to do with the murder.
Joey and Watson catch up over coffee. Joey dropped out of school and is about to buy a bar with a friend. Joey asks Watson if she is interested in investing in his business.
Watson heads over to the murder house and finds a shirtless man reading the math on the walls. He says Sherlock is downstairs. Sherlock tells her that the man is Harlan Emple, a professor from the university. Watson asks if the man was actually killed for his math and Sherlock says that is for Harlan to find out. Watson asks for a $5,000 advance in order to loan Joey the money. Harlan calls to them that he figured the formula out. Harlan explains that the math solution is the farthest he has ever seen this problem taken. The prize for this problem is $1,000,000. There is a whole community dedicated to this problem. Harlan offers to put them in contact with a friend of his.
Sherlock and Watson meet with Tanya Barrett, a professor at a nearby college. She offers to walk them through the names of people connected to the problem. Sherlock matches the handwriting from the house to a sample in one of Tanya's books. She shows him a picture of their suspect, Cyril Nower. He calls it in that they have a suspect and Bell tells him that there has been a second shooting victim. The weapon is the same gun that was used to kill Felix. Bell tells Sherlock that the second victim is Cyril Nower.
Watson suggests that the two mathematicians have been murdered by someone else who is trying to solve the problem. Dog hairs were found on Cyril's jacket and Sherlock thinks that the shooter may own a dog. Watson again brings up the topic of the advance. Sherlock correctly guesses that it is related to her patient that died in her care a few years ago. He only wants to ensure that Watson is not being taken advantage of. Watson explains her patient's case. She made a mistake and the man bled to death. A few weeks before the surgery she got to know his family. After the accident the wife sued her but the son wrote her a letter that said he forgave Watson and didn't think it was her fault. This isn't the first time Joey has asked for money from Watson.
At Cyril's place, Bell has found a bug in one of the fixtures. Sherlock notices a CCTV pointed directly at his apartment from across the street. He jumps onto a taxi and takes down the camera. He finds something that allows the camera to be hijacked.
Sherlock, Bell and Watson visits Roe Encryption. They found his signal jammer on the security camera and says the person who put it there may be responsible for his death. Roe admits they were spying on him. Roe says that while the math proof would only offer mathematicians $1,000,000 it would offer his company much more. The solved problem could render all encryption obsolete. Watson asks how this is possible and he explains that it could be used to make a sort of skeleton key. Roe offered to fund Cyril if he helped to create technology to defend against the skeleton key. Roe found out that Felix started working with Cyril when he turned Roe's offer down. Roe says that according to Tanya Barrett they were nowhere near a solution.
The team brings Tanya in for questioning. She admits that she lied to Roe about the work. They were only a third of the way through with years to still go. She thought that one bad thing would cancel out another. Sherlock found that Tanya owns the same type of dog as the hair found on Cyril. She also is the owner of the same type of gun that was the weapon in two murders. During the time of the murders Tanya claims she was at a restaurant with a friend.
Bell manages to recover the security footage from the restaurant and they see that Tanya was there the whole night so she can't be the shooter.
Sherlock has set up a wall of possible suspects that are working to solve the problem. He also decides, against his better judgement, to loan Watson the money she wanted. Sherlock warns her to watch out for Joey because he will use her guilt to his advantage. Watson opens the money package and finds that Sherlock has given her over 4x the amount of money she asked for. He tells her to use it to get out of any future dealings with Joey. Watson suggests that Tanya may have had a partner and Sherlock brings up the idea that she is being framed.
Sherlock meets with Tanya and tells her what he suspects. He asks if she has any enemies and she says that she recently got out of a long term relationship. Her ex-boyfriend was very angry and sent threatening emails.
The ex-boyfriend is brought to the station for questioning. Sherlock shows the emails that threaten Tanya and this allowed them to get a warrant for his account. The boyfriend ordered ammunition online and Bell thinks that he may have had more mathematicians in his sight.
The homeless man who was shot is finally awake so Sherlock, Watson, and Bell visit him in the hospital. The man describes his shooter and the description matches Tanya Barrett.
Sherlock talks through the case with Watson and they end up going in circles. Watson examines the video again and finds that a man pays for beer rather cheaply. She deduces that Tanya must have been there during happy hour.
The team confronts Tanya in her classroom about all of the evidence they have. Sherlock accuses her of murdering the mathematicians and planting the emails on her ex-boyfriend's email account.
Watson meets with Joey and offers to give him the money if he uses it for his engineering degree.
Sherlock reads the math problem for the last time. The FBI has asked that the police surrender everything surrounding the case, including Tanya. She has no notes on the problem and she wanted to cut a deal where she gave the solution in exchange for her freedom. The FBI wasn't interested though and Sherlock thinks that the math problem will remain unsolved for now. Watson explains what happened with Joey. Sherlock offers to go the cemetery with Watson next time she goes, in order to pay respects to the man who helped form who she is today.