Elevator Hall Number
Time limit8sMemory limit512 MB
Count how many distinct decimal strings can be formed by concatenating one chosen floor from each of N elevators, where each floor is between 1 and 99.
- Level
Medium6 of 10
- Topics
- Brute force, Hash map, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
JAG (Japanese Alumni Group) is a mysterious organization headquartered in a high-rise building somewhere in Tokyo. The building has elevators, and the -th elevator stops at every floor from to ().
X, a new JAG staff member, reached the elevator hall of the building to visit the headquarters. While waiting for an elevator after pressing the button, X noticed that the display showing the current floor of each elevator is somewhat unusual. When the -th elevator is on floor , the display shows one number obtained by listing in this order and concatenating them in decimal notation, without leading zeros and without spaces. For example, when and the elevators are on floors , , and in order, the display shows .
X became curious about how many different numbers can appear on the display. Your task is to write a program that computes this count.
Input
The input consists of multiple datasets, each in the following format.
...
The first line of a dataset contains the integer (), the number of elevators. The -th of the following lines contains two integers and (), the range of floors served by the -th elevator.
The end of the input is indicated by a line containing a single zero.
Output
For each dataset, output on one line the number of different numbers that can appear on the display.