Power Levels (Small)
Time limit5sMemory limit512 MB
For each given digit count D, find the smallest E whose 9000 multifactorial has fewer digits, or output dots when none exists.
- Level
Medium4 of 10
- Topics
- Math, Brute force
- Solved
- No attempts yet
Problem
A multifactorial is written as an integer followed by exclamation points, where . Its value is the product of every that is positive, taken over all nonnegative integers . Ordinary factorials fit this definition.
The other multifactorials of 5 are these.
Five followed by five or more exclamation points equals 5 every time. A 5 with no exclamation points is not a multifactorial.
The villain Anima and her underling Minera love three things: multifactorials, yelling IT'S OVER 9000 followed by some exclamation points, and roaming the universe looking for someone to fight.
When they meet a possible opponent, Anima asks Minera to measure the opponent's power level with her scanner. A power level is always a positive integer with no leading zero. Today the scanner display is blurry, so Minera can only report the number of digits in the power level, not the digits themselves.
Anima wants to yell IT'S OVER followed by a multifactorial of 9000 that describes the opponent's power level accurately. She never says anything that might be false, and she never uses more exclamation points than she needs. Take . Since also has 31682 digits, the opponent's power level might be at most , so Anima cannot yell IT'S OVER 9000!. But has fewer than 31682 digits, so the power level is certainly greater than and IT'S OVER 9000!! is always true. The power level also beats and , yet Anima refuses to spend extra exclamation points, so here she yells IT'S OVER 9000!!.
If no multifactorial of 9000 is certainly smaller than the opponent's power level, Anima stays dramatically silent. Silence is written as the ellipsis ....
Work out what Anima yells.
Input
The first line contains the number of test cases . Each of the next lines contains one integer , the number of digits in an opponent's power level.
Limits
Output
For each test case, print one line in the form Case #x: y. Here is the test case number starting from 1. If Anima must stay silent, is .... Otherwise is IT'S OVER 9000 followed by the smallest number of exclamation points that works. Use the ASCII apostrophe U+0027.
Hint
For , every multifactorial of 9000 is at least 9000, so a one digit power level cannot exceed any of them.
The answer for carries 1990 exclamation points.
For , 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 gives a true claim, and Anima picks the smaller count.