Counting Pretty Numbers Codechef Solution

Hello Programmers In this post, you will know how to solve the Counting Pretty Numbers Codechef Solution. The Problem Code: NUM239

Ezoicreport this adCounting Pretty Numbers Codechef Solution
Counting Pretty Numbers Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Vasya likes the number 239239. Therefore, he considers a number pretty if its last digit is 22, 33 or 99.

Vasya wants to watch the numbers between LL and RR (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 TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains two space-separated integers LL and RR.

Output

For each test case, print a single line containing one integer — the number of pretty numbers between LL and RR.

Constraints

  • 1≤T≤1001≤T≤100
  • 1≤L≤R≤1051≤L≤R≤105

Subtasks

Subtask #1 (100 points): original constraints

Input

2

1 0

11 33

Output

3

8

Explanation

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

Example case 2: The pretty numbers between 1111 and 3333 are 1212, 1313, 1919, 2222, 2323, 2929, 3232 and 3333.

Counting Pretty Numbers CodeChef Solutions in CPP

#include<iostream>
using namespace std;
bool isPrettyNumber(int number)
{
    // Get last digit of the number
    int single_digit = number % 10;
    if (single_digit == 2 || single_digit == 3 || single_digit == 9)
        return true;
    else
        return false;
}
int main()
{
    int test_cases;
    int a, b, counter;
    cin >> test_cases;
    while (test_cases--)
    {
        counter = 0;
        cin >> a >> b;
        for (int i = a; i <= b; i++)
        {
            if (isPrettyNumber(i))
                counter++;
        }
        cout << counter << endl;
    }
    return 0;
}

Disclaimer: The above Problem (Counting Pretty Numbers) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Mutated Minions Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad