program LotteryCombinations;
{
This program computes the total number of lottery combinations for:
- choosing 6 numbers out of 37
- choosing 1 power number out of 7
Total combinations = C(37,6) * C(7,1)
It uses an efficient multiplicative formula for binomial coefficients:
C(n, k) = product(i = 1..k) of (n - k + i) / i
This avoids huge factorials (e.g., 37! is far too large for 64-bit integers)
and keeps intermediate values small and exact.
}
{$mode objfpc}{$H+}
function BinomialCoefficient(n, k: UInt64): UInt64;
var
i: UInt64;
resultValue: UInt64;
begin
if k > n then
begin
Result := 0;
Exit;
end;
{ Use symmetry: C(n, k) = C(n, n-k) }
if k > n - k then
k := n - k;
resultValue := 1;
{ Multiplicative formula }
for i := 1 to k do
resultValue := resultValue * (n - k + i) div i;
Result := resultValue;
end;
var
mainN, mainK: UInt64;
powerN, powerK: UInt64;
mainCombos, powerCombos, totalCombos: UInt64;
begin
mainN := 37;
mainK := 6;
powerN := 7;
powerK := 1;
{ Compute combinations }
mainCombos := BinomialCoefficient(mainN, mainK);
powerCombos := BinomialCoefficient(powerN, powerK);
totalCombos := mainCombos * powerCombos;
{ Output results }
WriteLn('Main combinations (C(37,6)): ', mainCombos);
WriteLn('Power combinations (C(7,1)): ', powerCombos);
WriteLn('Total lottery combinations: ', totalCombos);
end.
{
run:
Main combinations (C(37,6)): 2324784
Power combinations (C(7,1)): 7
Total lottery combinations: 16273488
}