Lucky Number Scores

Problem #491  

Tags: unlabeled

Who solved this?

No translations... yet

Many thanks to Clive Fraser for creating this problem!

Mary likes the digits 3 and 7. She thinks that any numbers which contain both of these digits are lucky numbers. If a number contains both digits multiple times then it is even luckier. Mary decided on a simple scoring system to determine just how lucky a number is. She simply counts the number of 3s in the number and then counts the number of 7s in the number. The score is then the product of these two counts.

For example, the number 74353723 scores 6 because there are 2 7's and 3 3's and 2 x 3 = 6. Similarly 37 scores 1, 3737 scores 4, 7654 scores 0, 336532333 scores 0 and 77771333 scores 12.

Mary went on to think about ranges of numbers and realised that she could determine how lucky a range of numbers is, by adding together the lucky number scores of all the numbers in the range.

In this problem you will be given a number of ranges and, for each of these, you are asked to find the lucky number score for the range, inclusive of the first and last numbers.

Consider the range of 14 numbers from 730 to 743. Three of the numbers (740, 741, 742) have no score. Nine of the numbers (730, 731, 732, 734, 735, 736, 738, 739, 743) have a score of 1 and two of the numbers (733, 737) have a score of 2. This gives a total score of 13 for the range. You will be given a number of different ranges in the problem but the larger of the two numbers in the range will always be less than 3 x 10^18.

Input/Output description: The first line of the input data will contain a single integer N, the number of ranges to process. N lines will follow. Each line contains two numbers n1 and n2, separated by a space. Find the total of the lucky number scores for all numbers in the range, from n1 to n2 inclusive. Combine all answers into a single string, separated by spaces.

Example:

input:
4
730 743
112 901
1726 23073
14611 297906

answer:
13 56 2496 58087
You need to login to get test data and submit solution.