Algorithm
problem link ; https://www.codechef.com/problems/NUM239
Problem
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Vasya likes the number . Therefore, he considers a number pretty if its last digit is , or .
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
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
2 1 10 11 33
3 8
Explanation:
Example case 1: The pretty numbers between and are , and .
Example case 2: The pretty numbers between and are , , , , , , and .
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
1 10
11 33
Output
8
Demonstration
CodeChef solution NUM239 - Counting Pretty Numbers Codechef solution in C,C++