How to implement the algorithm of executing prisoners by php in solving Joseph problem
This article mainly introduces how to implement the php Joseph problem solving algorithm for the execution of prisoners, the article introduces in great detail, has a certain reference value, interested friends must read it!
The specific analysis is as follows:
In ancient times, a judge wanted to sentence IV prisoners to death. He had an absurd law that made prisoners stand in a circle. From the beginning of the second person, every D person was pulled out to be executed, and then D was counted, and then pulled out for execution. Until the last one can be pardoned.
Function getNum ($n quotient m) {/ / is used to initialize all the numbers in the array $a = array (); / / traverses, and stores it into the array for ($iposi1 * * i1) {/ / if the item in the array is greater than 1, continue to loop out the element / / delete the rule for ($job1 * j