edit: The other answers do an excellent job of describing the difference between pythagorean and tempered tuning systems and the related maths, so this answer is to add additional information regarding the other part of the question as well as a followup answer the original poster added. I'm assuming that "nicest" in this case means "consonant". edit
Historically the intervals based on ratios can be traced back to Pythagoras. To quote a book on the subject:
After researching what notes sounded pleasant together Pythagoras
worked out the frequency ratios (or string length ratios with equal
tension) and found that they had a particular mathematical
So to address the followup question from the OP:
I think I made a mistake in my question...
the perfect fifth is a result of the nicest ratio of LENGTH of strings
that Pythagoras the mathematician found. So octave was 1/2, and
perfect fifth was 2/3 of the length of the string. He found that after
the octave the perfect fifth was most consonant sounding. Because
after splitting the string into 2 equal pieces, he then split it into
3 equal pieces and that's how he found the perfect fifth ratio. Why is
2/3 nicer than 1/3 is beyond me.
edit The mathematics and perception of tone and intervals was researched by Hermann Von Helmholtz, and his work on the subject "Sensations of Tone" still stands as an excellent resource and information. edit
Why a perfect 5th is considered the most consonant interval other than the octave has to do with how the waveforms of the pitches interact with each other.
Assuming a sine wave (no harmonics, pure tone) for each pitch, the combination of two pitches will create more or less complex patterns depending on the interval. It has to do with the way waves combine.
An imperfect example would be waves on a pond. If you throw two rocks into a pond and the waves line up, you get waves flowing together, some becoming larger, others fitting in between each other. If the waves don't line up, you get square peaks in an interference pattern.
Here is a picture of some of the intervals with their waves combined:
The site the image is from has a good description of density degree.
The perfect 5th has the simplest form with the fewest peaks and valleys, making a smooth sounding tone. More peaks and valleys in a tone we will hear as a dissonance or "grinding" sound. The only thing smoother than the 5th would be an octave, or 2:1 ratio.