pythonalgorithmsquare-root

Finding square roots in surd form


I'm trying to build a program that let's you multiply two square roots and display the answer in surd form if the answer isn't an integer.

I've seen answers here and here, although I don't understand C++ and C#, so I don't have a clue on what to do. The first thing I've done is multiply the two numbers inside the square roots together, then I can display the answer if it is an integer, but if it isn't it completely messes up.


Solution

  • I don't see a better way than by factoring the given numbers, summing the multiplicities of the prime factors, extracting the even parts of the multiplicities and forming the square root of the products.

    E.g.

    √(84.375)=√(2²3.7.3.5³)=√(2²3²5³7)=2.3.5√(5.7)=30√35