시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 1 | 1 | 1 | 100.000% |
In Panda Land, pandas have their own numeral system to represent a number. Surprisingly, this numeral system is similar to the famous Roman Numerals in our ancient civilization. Although pandas are aware about numeral system, they can not write (imagine how can a panda write!). Instead, they cut and arrange bamboos to form a number.
These are the production rules of Panda Number:
The aforementioned rules imply that there is exactly one representation in Panda Number for each number in decimal system.
Unlike those Roman Numerals, pandas do recognize zero and negative number (which prove pandas are more advanced than our ancient Romans). To represent a negative number, they add one bamboo as a negative sign in front of the letters. Zero is a special number which doesn't fall into any rules above. To form a zero, pandas need five bamboos.
The number of bamboos needed to form a number is the sum of required bamboos for each letter that appears in that number. For Example:
Given two numbers A and B, find out how many bamboos needed by panda to form (remember, they can't write) all number between A and B inclusively.
Decimal | Panda Number | Required Bamboo |
---|---|---|
1 | I | 1 |
5 | V | 2 |
10 | X | 2 |
50 | L | 2 |
100 | C | 3 |
500 | N | 3 |
1,000 | M | 4 |
5,000 | E | 4 |
10,000 | W | 4 |
50,000 | F | 3 |
100,000 | Y | 3 |
500,000 | K | 3 |
1,000,000 | H | 3 |
5,000,000 | T | 2 |
10,000,000 | A | 3 |
The input begins with a single positive integer T in a line indicating the number of test cases. Each case contains two numbers A and B (-25,000,000 <= A <= B <= 25,000,000) in a line.
For each case, print in a single line the number of needed bamboos to form all numbers between A and B (inclusive).
7 -1 1 4018 4019 -25000000 25000000 -100 -57 -100 0 0 100 43 100
8 28 2121000021 399 778 678 434
ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2007 E번