A – Not
Should be easy as long as you know the basics of your chosen programming language. Can be computed with an if/else statement, the ternary operator (ans = x == 1 ? 0 : 1
), or the xor operator (ans = x ^ 1
)
B – Product Max
Answer is one of: $$$a \cdot c, a \cdot d, b \cdot c, b \cdot d$$$; find the maximum of these and print it.
Proof by exchange argument: No matter what you pick $$$x$$$ to be, you can improve the product by either maximizing or minimizing $$$y$$$, based on the sign of $$$x$$$. Same argument applies when $$$x$$$ and $$$y$$$ are swapped.
C – Ubiquity
There are $$$10$$$ possible digits among $$$n$$$ positions, thus the total number of sequences that satisfy the first constraint is $$$10^n$$$.
Now we want to subtract sequences that violate the second or third constraints. We can construct 9^n sequences without any $0$s (violating the second constraint), same with sequences without any $9$s (violating the third constraint).
However if we subtract $$$2 \cdot 9^n$$$, note that we have removed the sequences that violate both the second and third constraints twice. There are 8^n such sequences (as they lack both $0$s and $9$s), so we add them back to get the correct count. This pattern of overcounting, adding, overcounting, removing, repeat until final accurate count is known as the inclusion-exclusion principle.
Final answer is thus $$$10^n - 2 \cdot 9^n + 8^n$$$. This can be calculated in $$$O(n)$$$ via repeated multiplication, or $$$O(\log n)$$$ via fast exponentiation. If you don't know how to work with large numbers under a modulus, see my tutorial on that subject.