|MadSci Network: Evolution|
Cool question… First, we should appreciate that the differences between centipedes (Class Chilopoda) and millipedes (Class Diplopoda) are not limited to the number of legs per segment. These organisms also generally occupy different ecological niches. Centipedes are generally carnivorous, while millipedes are thought to feed primarily on organic debris or detritus. Centipedes are also generally faster than millipedes, which facilitates their carnivorous lifestyle.
It is difficult to appropriately infer what positive selective pressures (if any) are responsible for the specific adaptive difference (segmentation/leg- number). Different mutations in centipede and millipede lineages may have become fixed due to random processes of genetic bottlenecks (http://en.wikipedia.org/wiki/Population_bottleneck) or genetic drift (http://en.wikipedia.org/wiki/Genetic_drift), or there may have been positive selection due to increased reproductive fitness caused by the possession of a particular trait (e.g., a particular segmentation genetic program).
Both groups are able to occupy distinct niches; mutations differentiating centipedes and millipedes include, but are not limited to, a group of genes called HOX genes involved in body plan organization and assigning "segmental identity" in systems ranging from the fruit fly to the developing human brain. HOX genes (along with a suite of other genes involved in body plan specification) have well-characterized functions influencing segment number, limb number, etc. Changes in the number (via gene duplication: http://en.wikipedia.org/wiki/Gene_duplication) and activity of HOX genes can arise through evolution, allowing new body forms a chance to survive/thrive. Unfavorable adaptations/mutations that influence segmentation/body plan will be less likely to proliferate in certain ecosystems; "unfit" forms fail to persist in the population. In the case of Myriapods, the specific environment probably partially dictates whether a centipede or millipede lineage would be more successful.
A nice website describing some basics of the evolutionary and developmental biology of segmentation in Myriapods: http://www.salk.edu/labs/mnl-t/clh/pede2.html
A more complex paper discussing the evolutionary lineage of centipedes and millipedes: http://dpc.uba.uva.nl/ctz/vol73/nr03/art02
Hope this helps,
Try the links in the MadSci Library for more information on Evolution.