Hardy–Ramanujan number generalization
APL  45  41
{⍺←1⋄2≤+/,⍺=(v∘.≤v)×∘.+⍨⍵*⍨v←⍳⌊⍺*.5:⍺⋄⍵∇⍨⍺+1}

Shorter but slower version of 41 chars:
{⍺←1⋄2≤+/,⍺=(v∘.≤v)×∘.+⍨⍵*⍨v←⍳⍺:⍺⋄⍵∇⍨⍺+1}

You can try it online, just paste the function and invoke it with a number:
      {⍺←1⋄2≤+/,⍺=(v∘.≤v)×∘.+⍨⍵*⍨v←⍳⌊⍺*.5:⍺⋄⍵∇⍨⍺+1} 2
50
      {⍺←1⋄2≤+/,⍺=(v∘.≤v)×∘.+⍨⍵*⍨v←⍳⌊⍺*.5:⍺⋄⍵∇⍨⍺+1} 3
1729

(The algorithm is quite dumb though, don't expect the online interpreter to compute n=4)
The answer for n=2 is 50 = 5² + 5² = 7² + 1² because its a number that &quot;can be expressed as the sum of two squares of positive integers—doesn't say different—in two ways.&quot;
If you want to add the distinct clause, just change (v∘.≤v) into (v∘.&lt;v), same number of chars, and n=2 becomes 65:
      {⍺←1⋄2≤+/,⍺=(v∘.&lt;v)×∘.+⍨⍵*⍨v←⍳⌊⍺*.5:⍺⋄⍵∇⍨⍺+1} 2
65

I'm beating GolfScript? Can't be!!