Smith Numbers
Practice
4.3 (9 votes)
Approved
Math
Medium
Number theory
Open
Primality test
Prime factorization
Problem
56% Success 1870 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Smith numbers were named by Albert Wilansky of Lehigh University. He noticed the property in the phone number (493-7775) of his brother-in-law Harold Smith:

4937775 = 3 × 5 × 5 × 65837 and (4 + 9 + 3 + 7 + 7 + 7 + 5) = (3)+ (5) + (5) + (6 + 5 + 8 + 3 + 7) = 42.

In simple words, a number is said to be a Smith Number if its digit_sum is equal to the sum of digit_sums_of_all_its_prime_factors.

Input:

First line contains T which is the number of test cases.
T lines follow each containing two integers L and R.

Output:

For each range L to R (both inclusive), output the number of Smith Numbers in this range.

Constraints:

  • 1 ≤ T ≤ 106
  • 2 ≤ L ≤ R ≤ 107

Scoring:

  • 1 ≤ T ≤ 1000, 2 ≤ L ≤ R ≤ 10000: (30 pts)
  • Orginal Constraints : (70 pts)

Note:

Large IO. Use scanf/printf(in C/C++).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
ApprovedMathMediumNumber TheoryOpenPrimality test
Points:30
10 votes
Tags:
ApprovedImplementationMathMediumOpenPrimality test
Points:30
14 votes
Tags:
C++Primality TestsMathNumber Theory