Tutorial:
In this problem, you are asked to count the number of ways to choose exactly three bulbs to be turned on from a string of \( n \) bulbs, which is simply the combination "n choose 3" (i.e. \(\binom{n}{3}\)). The formula for this is:
\[
\binom{n}{3} = \frac{n \times (n-1) \times (n-2)}{6}
\]
Given that \( n \) can be as large as \( 10^{15} \), directly computing the product \( n \times (n-1) \times (n-2) \) might result in numbers that exceed the limits of built-in data types. To handle this, the solution first simplifies the expression by dividing by 6 before performing multiplications. This is done by taking the numbers \( n \), \( n-1 \), and \( n-2 \) and sequentially canceling common factors with 6 using the greatest common divisor (GCD). After the cancellation, the product is computed in a way that avoids overflow.
Because the resulting number can be extremely large, the solution uses a custom string multiplication function (mul) to multiply numbers represented as strings, which simulates big integer arithmetic. The final product, which is the answer to \(\binom{n}{3}\), is printed as a string.
Step-by-Step Overview:
1. Input Reading: Read the number of test cases and for each test case, read the integer \( n \).
2. Prepare Terms: Let \( a = n \), \( b = n - 1 \), and \( c = n - 2 \).
3. Simplify the Fraction: Initialize \( x = 6 \) (the denominator). For each of \( a \), \( b \), and \( c \), use the GCD to cancel factors from \( x \) so that division by 6 is handled exactly, which avoids overflow.
4. Multiply with Big Integer Arithmetic: Use a custom string multiplication function to multiply the simplified numbers together. The multiplication is performed on string representations of the numbers to handle the extremely large result.
5. Output: Print the resulting product, which represents the number of ways three bulbs can be turned on.
This method efficiently computes \(\binom{n}{3}\) even for very large \( n \), taking care of precision issues with large numbers by using big integer simulation via strings.