Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
There is a formula in wikipedia for the general case of josepus problem
But there is no reference for it, I don't know where it came from and I need too find out...
Maybe Donald Knuth's Art of Programming?
In "Concrete Mathematics" by Graham, Knuth, Patashnik. Look in Chapter 3: Integer functions.
Required, but never shown