2041: [USACO 2024 December Contest, Bronze] Problem 1. Roundabout Rounding
题目描述
Bessie the cow is back in school! She has started doing her math homework in which she is tasked to round positive integers to powers of
.To round a positive integer
to the nearest , where is a positive integer, Bessie first locates the 'th digit from the right. Let denote this digit.If
, Bessie adds to .Then, Bessie sets all the digits including and to the right of the
'th digit from the right to be .For instance, if Bessie wanted to round
to the nearest (hundred), Bessie would first locate the nd digit from the right which is . This means . Then since , Bessie adds to . Finally, Bessie sets all the digits in to the right of and including the nd digit from the right to be , resulting in .However, if Bessie were to round
to the nearest , she would end up with .After looking at Bessie's homework, Elsie thinks she has invented a new type of rounding: chain rounding. To chain round to the nearest
, Elsie will first round to the nearest , then the nearest , and so on until the nearest .Bessie thinks Elsie is wrong, but is too busy with math homework to confirm her suspicions. She tasks you to count how many integers
at least and at most ( ) exist such that rounding to the nearest is different than chain rounding to the nearest , where is the smallest integer such that .输入
You have to answer multiple test cases.
The first line of input contains a single integer
( ) denoting the number of test cases. test cases follow.The first and only line of input in every test case contains a single integer
. All within the same input file are guaranteed to be distinct.输出
样例输入
4
1
100
4567
3366
样例输出
0
5
183
60
提示
Consider the second test case in the sample.
should be counted because chain rounded to the nearest is ( ), but rounded to the nearest is .In the third test case, two integers counted are
and . chain rounds to instead of to and chain rounds to instead of . However, is not counted since it chain rounds to which is rounded to the nearest .SCORING:
- Inputs 2-4:
- Inputs 5-7:
- Inputs 8-13: No additional constraints.