What is this myth/legend and origin of related ideas?

There is a story I recently heard but the story teller (who read about it someone on the Internet) have forgotten the majority of the story, so there is little I can work on: my search attempts went no where. Thus I was hoping to ask here if anyone know more about it. I'm sure there have been a question about this before, but as I said, I can't find it.

The story go as follow. A bunch of people (and the protagonist is among them) go fight somewhere, lost badly, and have to retreat. After holing up somewhere, they find no ways to escape. They decided to all commit suicide. But to ensure everyone really die, they decided to kill themselves instead, one by one. One person is chosen as the starting point. Then everyone (there are $n$ of them) stand in the circle. From the starting point, people count $m$ people clockwise and kill the unlucky guy who is the $m$-th person. After that, everyone return to their original position on the circle, and the process repeat, start counting from the guy just get killed. Note that those who are already killed no longer occupy a spot in the circle, so counting skip over them. This goes on until everyone dies (obviously, the last person is supposed to commit suicide).

However, the hero disapprove of that idea, not wanting to die, he tried to ensure he is the last person instead. And using $n$ and $m$, the hero managed to calculate the exact position, the $l$-th position clockwise from the starting person, such that by standing there he is the last one standing.

So my question is thus:

1. What is this story? The name of the characters, origin, and sources (links would be appreciated).

2. What is the formula relating $l$ to $n$ and $m$? And how to derive it? Links to resources that explain it is fine too.

3. What the traces of various attempts by ancient mathematician to solve this problem (eg. partial solution, solution without proof, attempts at special cases,etc.)?