A
The question asks how to stack towers such that each block carries on top of it blocks with sum of at most the durability of that block. In particular, the blocks all have the same weight and durability. Hence, the limiting factor for how many blocks can be stacked is the bottom block, namely it can carryblocks for a maximum ofblocks per tower. Ceil-Divide the total number of blocks by that and get the minimum number of towers required.
B
A number is beautiful iff where is the sum of digits of . In particular, we claim that . The reverse direction is trivial. For the forward direction, consider the contrapositive, namely . Specifically, consider arbitrary with and . We claim that This is because this requires for all , which is impossible since and .
Hence from above, we know is beautiful .
To reduce the sum of the digits to under 9, we greedily reduce the sum of the digits by removing the largest ones first. We remove the digits until there are no more left.
Remember the edge case that the leading digit cannot be less than 1. Hence, we register the leading digit as one less in the frequency table, namely treating it as if we could remove n-1 from the sum.
C
We can solve this problem with binary search. Namely, we can find as whether a sequence of of length can meet the conditions is monotonic.
Consider a particular . We will try to kill all of the bits of seperatly. In particular, for a given set bit of , namely (set bit at position ), we find some such that . Namely, we need copies of . In the beginning, we say there are copies of to use for each (in particular each can have up to all bits set). We subtract as described above, and if and only if there is always enough s to subtract then there is a solution.
D
We solve this problem with an approach similar to a prime number sieve. We keep such that gives the number of unique elements of which divide . This can be constructed by iterating through all elements of (namely ), then incrementing .
We can consider three types of elements, elements which are divisible by all , elements which are divisible by some , and all of the elements. We let be the elements in the first set, be the elements in the second set but not in the first set (divisible by some but not all ), and which are the rest (namely divisible by no ). Alice can kill a number if there is some element of which divides it. Namely, Alice can kill the elements in . Bob can kill a number if NOT all elements of can divide it. Namely, Bob can kill the elements in .
Suppose there were only elements in . We claim that the first grabber wins .
If , then the winner of grabbing (described above) can force a win by forcing a win condition on , and copying the opponent on . If or , then the greater of and can force a win by using their extra number to force the other player to be the disadvantaged grabber in .