CNTLUCKN - Editorial

PROBLEM LINK:

Practice
Contest

Author: Yash Shah
Tester: Roshan Gupta, Shivam Sarang, Hrishikesh Patel
Editorialist: Yash Shah

DIFFICULTY:

EASY

PREREQUISITES:

Math

PROBLEM:

Viraj likes the number 258. Therefore, he considers a number lucky if its last digit is 2, 5 or 8.

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

EXPLANATION:

Sample Test Case:

Input:
2
1 10
11 33

Output:
3
7

  • Test Case 1: The lucky numbers between 1 and 10 are 2,
    5 and 8.
  • Test Case 2: The lucky numbers between 11 and 33 are 12,
    15, 18, 22, 25, 28, and 32.

SOLUTIONS:

Setter's Solution
#include <stdio.h>

int main(void) 
{
    int T , L , R , i , j, count = 0;
    scanf("%d",&T);
    for(i=0;i<T;i++)
   {
        count = 0;
        scanf("%d %d",&L,&R);
        if(L>R)
       {
            L = L + R;
            R = L - R;
            L = L - R;
       }
    
        for(j=L;j<=R;j++)
        {
            if(j%10 == 2 || j%10 == 5 || j%10 == 8)
            {
                    Count = count + 1;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}