EDIT , due to a recent clarification of this post.
You will not be able to deal with a manual solution if you do not have a whole group of candidates of sciences and several years. The best advice I can give you is to buy a Mathematica (or other) license and associate it with your program.
If you're a Lisp programmer, using Maxima is another potential (free) solution.
If you need a background in modern art in summation algorithms, this document is a good start.
X1 + X2 + ... + Xk = n, where Xi is an integer and> = 0.
What is Standby X1 ^ 2 + ... Xk ^ 2?
Such problems take a lot of people to figure out how to do this on paper.
Take k = 2. Then X_1 + X_2 = n gives X_2 = n - X_1.
So, the expected calculation is E = X_1^2 + (n - X_1)^2 = 2 X_1^2 -2n X_1 + n^2 .
It reads
E = sum(p_k * (2 * k^2 - 2 * n * k + n^2), k = 0..infinity)
where p_k = Prob(X_1 = k) . Such amounts, depending on p_k , are usually very difficult to calculate. I would say that the problem is even more complicated than computational integrals in a closed form (for which no software fully implements the Risch algorithm, but cannot be analyzed).
To convince yourself, take for example. p_k = 1 / (log(k) * k^4) .
Finding a formula (or a formula generator) for her is at least a very complex research problem.