Samu and Special Coprime Numbers
Practice
4.5 (58 votes)
Dynamic programming
Open
Approved
Medium
Problem
49% Success 2294 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Samu had come up with new type of numbers, she named them Special Coprime numbers. Special Coprime numbers follow a property : A number N is said to be Special Coprime if sum of its digits as well as the sum of the squares of its digits are coprime to each other.

Now she started counting numbers that are Special Coprime. But soon she get bored and decided to write a program that can help do it. Now she want you to help her to find count of such numbers between L and R , where both L and R are included.

Input Format :
First line contain number of test cases T. Each test case contains two space separated integers L and R, denoting the range in which you need to find the count of Special Coprime numbers.

Output Format :
For each test case you need to print the count of such numbers in range [L,R]

Constraints :
1 ≤ T ≤ 103
1 ≤ L ≤ R ≤ 1018

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
Tags:
Dynamic ProgrammingAlgorithms3 DimensionalMedium
Points:30
25 votes
Tags:
Dynamic ProgrammingAlgorithmsMedium
Points:30
4 votes
Tags:
MediumAlgorithmsApproved