Given only the digit count D of a hidden integer, find the fewest exclamation marks E making the multifactorial of 9000 certainly smaller than it.
Medium6MathBrute forceNo attempts yetTime limit5sMemory limit512 MBA multifactorial is a number N followed by E exclamation points, where E≥1. Its value is the product of every positive N−K×E over the nonnegative integers K. An ordinary factorial fits this definition:
5!=5×4×3×2×1=120
The other multifactorials of 5 are
5!!=5×3×1=15
5!!!=5×2=10
5!!!!=5×1=5
and 5 followed by five or more exclamation points is 5. A 5 with no exclamation point at all is not a multifactorial.
The villain Anima and her underling Minera like three things: multifactorials, shouting IT'S OVER 9000 with some exclamation points after it, and travelling the universe looking for someone to fight.
When they meet an opponent, Anima tells Minera to measure the opponent's power level with her scanner. A power level is a positive integer written without a leading zero. Today the scanner display is blurry, so Minera can report only the number of digits D in the power level, and none of the digits themselves.
Anima wants to shout IT'S OVER and then a multifactorial of 9000 that describes the opponent correctly. She never shouts anything that might be false, and she never uses more exclamation points than she needs. Suppose D=31682. She cannot shout IT'S OVER 9000!, because 9000! also has 31682 digits, so the opponent's power level might be a 31682-digit number that is at most 9000!. The value 9000!! has fewer than 31682 digits, so the power level is certainly larger than 9000!! and IT'S OVER 9000!! is guaranteed to be true. The power level is certainly larger than 9000!!! and 9000!!!! as well, but Anima keeps the number of exclamation points as small as she can, so she shouts IT'S OVER 9000!!.
If no multifactorial of 9000 is certainly smaller than the opponent's power level, Anima says nothing. Her silence is written as the ellipsis ....
What does Anima shout?
The first line contains the number of test cases T. Each of the next T lines contains one positive integer D, the number of digits in an opponent's power level.
For each test case, print one line of the form Case #x: y. Here x is the test case number starting from 1, and y is either ... when Anima says nothing, or IT'S OVER 9000 followed by one or more exclamation points. Match the format exactly. The apostrophe is the ASCII character ' (U+0027).
When D=1 the power level is a single digit, and every multifactorial of 9000 is at least 9000, so Anima says nothing.
When D=206, both 9000 with 156 exclamation points and 9000 with 157 exclamation points have 205 digits, while 9000 with 155 exclamation points has 207 digits. Either 156 or 157 makes a true claim, and Anima picks 156 because it is the smaller one. Adding one exclamation point does not always reduce the digit count, so the smallest workable count has to be searched for.