# Problem 585: Nested square roots ![graphic](img585.gif) Consider the term \$\\small \\sqrt{x+\\sqrt{y}+\\sqrt{z}}\$ that is representing a nested square root. \$x\$, \$y\$ and \$z\$ are positive integers and \$y\$ and \$z\$ are not allowed to be perfect squares, so the number below the outer square root is irrational. Still it can be shown that for some combinations of \$x\$, \$y\$ and \$z\$ the given term can be simplified into a sum and/or difference of simple square roots of integers, actually denesting the square roots in the initial expression. Here are some examples of this denesting: \$\\small \\sqrt{3+\\sqrt{2}+\\sqrt{2}}=\\sqrt{2}+\\sqrt{1}=\\sqrt{2}+1\$ \$\\small \\sqrt{8+\\sqrt{15}+\\sqrt{15}}=\\sqrt{5}+\\sqrt{3}\$ \$\\small \\sqrt{20+\\sqrt{96}+\\sqrt{12}}=\\sqrt{9}+\\sqrt{6}+\\sqrt{3}-\\sqrt{2}=3+\\sqrt{6}+\\sqrt{3}-\\sqrt{2}\$ \$\\small \\sqrt{28+\\sqrt{160}+\\sqrt{108}}=\\sqrt{15}+\\sqrt{6}+\\sqrt{5}-\\sqrt{2}\$ As you can see the integers used in the denested expression may also be perfect squares resulting in further simplification. Let F(\$n\$) be the number of different terms \$\\small \\sqrt{x+\\sqrt{y}+\\sqrt{z}}\$, that can be denested into the sum and/or difference of a finite number of square roots, given the additional condition that \$0