Ishan.nitj's blog

By Ishan.nitj, history, 9 years ago, In English

Can any one explain the logic behind this question from hackerearth: 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 ≤ 1e3 1 ≤ L ≤ R ≤ 1e18

Link: https://www.hackerearth.com/problem/algorithm/samu-and-special-coprime-numbers/description/

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it +3 Vote: I do not like it

It uses this technique Blog. It is sad that there are test cases set such that this type of solution only pass! I wrote a program which uses bottom up to count the same property between L,R but it won't pass as it is another way round! That is why I stick to CodeForces! :D Just in case as my solution is such a waste and I am sad, if it helps you can check it out Ideone