Let $\triangle XOY$ be a right-angled triangle with $\angle XOY=90^\circ$.  Let $M$ and $N$ be the midpoints of legs $OX$ and $OY$, respectively.  Find the length $XY$ given that $XN=22$ and $YM=31$.
1. Let $\triangle XOY$ be a right-angled triangle with $\angle XOY = 90^\circ$. Let $M$ and $N$ be the midpoints of legs $OX$ and $OY$, respectively. We are given that $XN = 22$ and $YM = 31$.

2. Let $OX = a$ and $OY = b$. Since $M$ and $N$ are midpoints, we have:
   \[
   MX = \frac{a}{2} \quad \text{and} \quad NY = \frac{b}{2}
   \]

3. Using the distance formula, we can write the given distances as:
   \[
   XN = \sqrt{OX^2 + NY^2} = \sqrt{a^2 + \left(\frac{b}{2}\right)^2} = 22
   \]
   \[
   YM = \sqrt{OY^2 + MX^2} = \sqrt{b^2 + \left(\frac{a}{2}\right)^2} = 31
   \]

4. Squaring both equations, we get:
   \[
   a^2 + \left(\frac{b}{2}\right)^2 = 22^2 = 484
   \]
   \[
   b^2 + \left(\frac{a}{2}\right)^2 = 31^2 = 961
   \]

5. Simplifying the equations, we have:
   \[
   a^2 + \frac{b^2}{4} = 484
   \]
   \[
   b^2 + \frac{a^2}{4} = 961
   \]

6. To eliminate the fractions, multiply the first equation by 4:
   \[
   4a^2 + b^2 = 1936
   \]

7. Now we have the system of equations:
   \[
   4a^2 + b^2 = 1936
   \]
   \[
   a^2 + \frac{b^2}{4} = 484
   \]

8. Multiply the second equation by 4:
   \[
   4a^2 + b^2 = 1936
   \]
   \[
   4b^2 + a^2 = 3844
   \]

9. Subtract the first equation from the second:
   \[
   4b^2 + a^2 - (4a^2 + b^2) = 3844 - 1936
   \]
   \[
   3b^2 - 3a^2 = 1908
   \]
   \[
   b^2 - a^2 = 636
   \]

10. Add the equations $4a^2 + b^2 = 1936$ and $b^2 - a^2 = 636$:
    \[
    4a^2 + b^2 + b^2 - a^2 = 1936 + 636
    \]
    \[
    3a^2 + 2b^2 = 2572
    \]

11. Solve for $a^2$ and $b^2$:
    \[
    3a^2 + 2b^2 = 2572
    \]
    \[
    b^2 - a^2 = 636
    \]

12. Multiply the second equation by 2:
    \[
    2b^2 - 2a^2 = 1272
    \]

13. Add the equations:
    \[
    3a^2 + 2b^2 + 2b^2 - 2a^2 = 2572 + 1272
    \]
    \[
    a^2 + 4b^2 = 3844
    \]

14. Solve for $b^2$:
    \[
    4b^2 = 3844 - a^2
    \]
    \[
    b^2 = \frac{3844 - a^2}{4}
    \]

15. Substitute $b^2$ back into $b^2 - a^2 = 636$:
    \[
    \frac{3844 - a^2}{4} - a^2 = 636
    \]
    \[
    3844 - a^2 - 4a^2 = 2544
    \]
    \[
    3844 - 5a^2 = 2544
    \]
    \[
    5a^2 = 1300
    \]
    \[
    a^2 = 260
    \]

16. Substitute $a^2 = 260$ back into $b^2 - a^2 = 636$:
    \[
    b^2 - 260 = 636
    \]
    \[
    b^2 = 896
    \]

17. Finally, find the length $XY$:
    \[
    XY = \sqrt{a^2 + b^2} = \sqrt{260 + 896} = \sqrt{1156} = 34
    \]

The final answer is $\boxed{34}$