- Joined
- Oct 24, 2012
- Messages
- 6,545
I am having a problem with the combination formula hitting the max ulong value to fast.
I was wondering if anyone could help me to improve the formula.
This is the factorial class i am using to get the factorial value from the numbers.
Here is the formula i am using.
Thanks for any and all help.
I was wondering if anyone could help me to improve the formula.
This is the factorial class i am using to get the factorial value from the numbers.
Code:
class Factorial
{
public static ulong Get(int factorial)
{
ulong count = 1;
ulong end = Convert.ToUInt64(factorial) + 1;
for (ulong i = 1; i < end; i++)
{
count = count * i;
}
return count;
}
}
Code:
public static ulong Total(int size, int groupSize)
{
return Factorial.Get(size) / (Factorial.Get(groupSize) * Factorial.Get((size - groupSize)));
}