At the start of the first month all of the doors are closed. Each person must walk down down the corridor, opening or shutting every P-th door, according to the given prime. For example, the soul assigned #5 opens or shuts doors 5, 10, 15, 20, etc.
At the end of a month they have all reached the end of the corridor, and they must start back, performing the operation in the opposite order. For example the #7 soul opens or closes doors 999994, 999987, 999980, 999973, and so forth.
How many months will it be before the doors are all closed again?