A religious sect builds shrines along a circle of radius 1000. The circle is cut into N arcs of equal length, and the N division points are numbered 1 through N in order. When N is 12, the points sit like the marks on a clock face.
Every circle has one or more sacred numbers. A sacred number is a divisor of N and is smaller than N. A shrine stands at each point whose number is a multiple of at least one sacred number. When N is 12 and the sacred numbers are 2 and 3, the shrines are at points 2, 3, 4, 6, 8, 9, 10, and 12.
On an inspection day the site closes and W workers leave the maintenance shed at the center of the circle at the same time. A worker visits every shrine assigned to that worker and then returns to the shed. Workers move in straight lines and distance is Euclidean. Each worker takes a shortest route that visits all the shrines assigned to that worker. Every shrine is assigned to at least one worker.
The site reopens only after the last worker is back at the shed, so the shrines have to be divided so that the distance walked by the worker who walks farthest is as small as possible. Find that smallest distance. When N is 12, the sacred numbers are 2 and 3, and 3 workers are available, the answer is about 3517.6.
The input holds one or more data sets. Each data set is one line of positive integers. The first three numbers are the number of workers W, the number of equal arcs N, and the number of sacred numbers D, followed by the D sacred numbers.
W is at most the total number of shrines, N≤8600, and D≤6. Every sacred number is a divisor of N and is smaller than N.
The last line holds a single 0 and means the input has ended.
For each data set print one line with the greatest distance a worker has to walk when the shrines are divided as well as possible. Round the value to one decimal place and always print that decimal place, even when it is 0.
The data is chosen so that every value within 0.005 of the exact minimum rounds to the same answer.
One input can hold many data sets, so the algorithm has to be fast enough.