# Having trouble evaluating this sum

I need help evaluating the following sum:
[img=http://img228.imageshack.us/img228/9540/sumln2.gif]

I tried writing a C++ program to help evaluate it, but because the factorials & exponents get so large the standard libraries cannot handle it nor any calculator I have. So I was hoping to get some advice on here. What would you recommend doing in order to solve this problem?

(I am in the process of getting MATLAB, never used it, and if there is no simpler solution I was planning on learning to use it to perhaps help solve it.)

Thanks...

• : I need help evaluating the following sum:
: [img=http://img228.imageshack.us/img228/9540/sumln2.gif]
:
: I tried writing a C++ program to help evaluate it, but because the
: factorials & exponents get so large the standard libraries cannot
: handle it nor any calculator I have. So I was hoping to get some
: advice on here. What would you recommend doing in order to solve
: this problem?
:
: (I am in the process of getting MATLAB, never used it, and if there
: is no simpler solution I was planning on learning to use it to
: perhaps help solve it.)
:
: Thanks...
:
Don't try to calculate 365! or (367-n)! or (1/365)^n; those individual values grow to fast outside the range of nearly all standard libraries.
Instead use maths to reduce those values. Write the first couple of n out. This will give you the following (I've left out the n*(n-1) for readability):
For n = 2:
[code]
365!/(365!) * (1/365)^2 = 1 * (1/365)^2
[/code]
For n = 3:
[code]
365!/(364!) * (1/365)^3 = 365 * (1/365)^3 = (365 / 365) * (1/365)^2
[/code]
For n = 4:
[code]
365!/(363!) * (1/365)^4 = 364*365 * (1/365)^4 =
(364 / 365) * (365 / 365) * (1/365)^2
[/code]
For n = 5:
[code]
365!/(362!) * (1/365)^5 = 363*364*365 * (1/365)^5 =
(363 / 365) * (364 / 365) * (365 / 365) * (1/365)^2
[/code]
As you can see the calculation can be reduced to a loop, which calculates (367-i)/365 and multiplies the results together. Finally the result of this loop can be multiplied by (1/365)^2 and n*(n-1). The result of each of these multiplication doesn't get very small or very large. The result may be quite small, but should be within limits of a standard library.
• You are absolutely right, thank you!