GOOD FORTUNE

# PROBLEM LINK:

https://www.codechef.com/SOUT2021/problems/GF001

*Author:* Aman Nadaf

*Tester:* Aman Nadaf

*Editorialist:* Aman Nadaf

# DIFFICULTY:

Simple

# PREREQUISITES:

NONE

# PROBLEM:

A boy named flick wants to buy some lottery tickets. so he visits a Fortune Teller to determine his lucky numbers for which he can win. the Fortune Teller tells him to buy Tickets whose number Ends with either 4,7 or 9.but the lottery counter has tickets of Numbers from Range L to R(both Inclusive).

so flick has to buy the tickets with numbers between L and R (both inclusive), so he asked you to determine how many Lucky numbers (numbers ending with either 4,7 or 9) are in this range so that he can buy all the tickets with his lucky numbers on it. Can you help him?

# EXPLANATION:

For Total numbers between given Range L to R (both Inclusive) u should find all the numbers (count of numbers) whose last digit ends with 4, 7 or 9 as we know if we divide any number by 10 the remainder will always be the last digit of that number so In case of programming languages we can use modulus operator (%) to find the remainder and count them if its equal to 4, 7 or 9. We use a loop to iterate between L to R.

# SOLUTIONS:

## Setter's Solution

‘’’

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define vi vector

#define vll vector

int main()

{

int t;

cin >> t;

while (t–)

{

int l, r, count = 0;

cin >> l >> r;

for (int i = l; i <= r; i++)

{

if (i % 10 == 4 || i % 10 == 7 || i % 10 == 9)

count++;

}

cout << count << endl;

}

}

‘’’

Feel free to share your approach here. Suggestions are always welcomed.

.