Algorithm


  problem link ;  https://www.codechef.com/problems/NUM239 

Problem

Read problems statements in Mandarin chineseRussian and Vietnamese as well.

Vasya likes the number 239. Therefore, he considers a number pretty if its last digit is 23 or 9.

Vasya wants to watch the numbers between  and  (both inclusive), so he asked you to determine how many pretty numbers are in this range. Can you help him?

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  and .

Constraints

  • 1≤�≤100
  • 1≤�≤�≤105

Subtasks

Subtask #1 (100 points): original constraints

Sample 1:

Input
 
Output
 
2
1 10
11 33
3
8

Explanation:

Example case 1: The pretty numbers between 1 and 10 are 23 and 9.

Example case 2: The pretty numbers between 11 and 33 are 12131922232932 and 33.

 

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include<stdio.h>
int main()
{
    int t,l,r,i,count;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&l,&r);
        count=0;
        for(i=l;i < =r;i++)
        {
            if(i%10==2 || i%10==3 || i%10==9) count++;
        }
        printf("%d\n",count);
    }
}.
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
1 10
11 33

Output

x
+
cmd
3
8
Advertisements

Demonstration


CodeChef solution NUM239  - Counting Pretty Numbers Codechef solution in C,C++

Previous
CodeCherf solution FLOW010 - ID and Ship Codecherf solution in C,C++
Next
CodeChef solution DOLL - Red Light, Green Light Codechef solution in C,C++