Counting Pretty Numbers

Sravani likes the number 239. Therefore, she considers a number pretty if its last digit is 22, 33 or 99.

Sravani wants to watch the numbers between 𝐿 and 𝑅 (both inclusive), so she asked you to determine how many pretty numbers are in this range. Can you help her?

Input

  • The first line of the input contains a single integer 𝑇 denoting the number of test cases. The description of 𝑇 test cases follows.
  • The first and only line of each test case contains two space-separated integers 𝐿 and 𝑅.

Output

For each test case, print a single line containing one integer — the number of pretty numbers between 𝐿L and 𝑅R.

Constraints

  • 1 ≤ 𝑇 ≤ 100
  • 1 ≤ 𝐿 ≤ 𝑅 ≤ 10^5

Subtasks

Subtask #1 (100 points): original constraints

Sample 1

InputOutput
2
1 10
11 33
3
8

Example case 1: The pretty numbers between 11 and 10 are 22, 33 and 99.

Example case 2: The pretty numbers between 11 and 33 are 12, 13, 19, 22, 23, 29, 32 and 33.


import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int test_cases = sc.nextInt();
        while(test_cases-->0){
            int L = sc.nextInt();
            int R = sc.nextInt();

            int count=0;
            for(int i=L; i<=R; i++){
                int last_digit = i%10;
                if(last_digit==2 || last_digit==3 || last_digit==9)
                    count++;
            }

            System.out.println(count);
        }
    }

    }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top