F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Simple Counting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 200    Accepted Submission(s): 66


Problem Description
¡¡¡¡Totalfrank and wlkilluajay have their lucky numbers. As we all know, 16 or any number contains 16 (116 for example) is lucky number for totalfrank and 2 or any number contains 2 (1723 for example) is lucky number for wlkilluajay.
¡¡¡¡Totalfrank is a normal guy who reads from left to right while wlkilluajay enjoys reading from right to left which means 16 to totalfrank is 61 to wlkilluajay.
¡¡¡¡Since their lucky numbers changes often, here is the simple counting question for you: given totalfrank¡¯s and wlkilluajay¡¯s lucky number and an interval, how many numbers in the given interval is at least a lucky number for one of them? Notice that wlkilluajay always read from right to left so a number which is outside the interval (in totalfrank¡¯s perspective) may be inside the interval when it is read from right to left (in wlkilluajay¡¯s perspective), you should also count that in (See samples for more details). By the way, because they read from different direction, 0 may be a problem (for example, if 2 is a lucky number for wlkilluajay, then 20, 200¡­ is also a lucky number for her. But when read from right to left, they are all just 2 and there may be infinite lucky numbers for her in a given interval in a normal guy¡¯s eyes). From this aspect, they decide to ignore any number contains 0.
 

Input
The input contains no more than 50 test cases.
The first line contains a single integer T indicating the number of test cases.
For each test case:
¡¡¡¡The first line of each test case includes two integers a (1 <= a <= 1018) and b (a <= b <= 1018).
¡¡¡¡The second line contains two integers c (1 <= c <= 1018) and d (1 <= d <= 1018). c is the lucky number for totalfrank and d is the lucky number for wlkilluajay (c and d won¡¯t contain any 0).
 

Output
For each test case, first you should print ¡°Case #x: ¡± (without quotes), where x stands for the case number started with 1 and then a single integer indication the answer to the question.
 

Sample Input
2 62 62 62 62 1 9999 53 23
 

Sample Output
Case #1: 2 Case #2: 501
 

Hint

For the first case, 62 is a lucky number for totalfrank and 26 is a lucky number for wlkilluajay (when read from right to left, it is 62 which fills in the interval
[62, 62]).So the answer is 2 (26 and 62).
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-04 10:15:47, Gzip enabled