Forget about the version I posted, it doesn't work.
I think your com(n, m) function is correct, but 180C164 is simply too large for unsigned long long. If you're only interested in the final result, you might wan't to use double instead. The final result doesn't need com(n, m) to be precise.
#include <cstdlib>
#include <cmath>
#include <iostream>
usingnamespace std;
double com(int n, int m)
{
double cnm = 1.0;
if (m * 2 > n)
m = n - m;
for (int i = 1; i <= m; n--, i++)
{
cnm /= i;
cnm *= n;
}
return cnm;
}
int main ()
{
double p = 0.5;
int n=180, k=164;
cout << com(n, k) << endl;
cout << com(n, k)*pow(1-p, k)*pow(p, n) << endl;
}
If you really need to calculate 180C164 precisely, you need to use a big integer package. You might be interested in the GNU MP Bignum Library, http://gmplib.org/