Codechef Problem: Counting Pretty Numbers Difficulty Rating:873

 

Problem



Vasya likes the number 239. Therefore, he considers a number pretty if its last digit is 2, 3 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 �.


Solution:



# cook your dish here


def is_pretty(number):

    last_digit = number % 10

    return last_digit == 2 or last_digit == 3 or last_digit == 9


def count_pretty_numbers_in_range(L, R):

    count = 0

    for number in range(L, R + 1):

        if is_pretty(number):

            count += 1

    return count


T=int(input())

li=[]

for _ in range(T):

    L,R=map(int,input().split())

    pretty_count=count_pretty_numbers_in_range(L,R)

    print(pretty_count)


Comments

Popular posts from this blog

Compress PDF using python step by step

Empty recycle bin using python step by step

Instagram automation in Python

Contact Form

Name

Email *

Message *