Numbers That Read the Same Upside Down
InterviewTime limit1sMemory limit128 MB
Count how many integers in the interval [m, n] stay the same when rotated 180 degrees, using the digit map 0, 1, 8, 6, 9.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Brute force, String matching
- Solved
- No attempts yet
Problem
The digits , , and look almost the same when the page is rotated degrees (turned upside down). The digit looks like a when rotated this way, and looks like a .
A multi-digit number can also look like itself when the page is turned upside down. For example, and do, but and do not.
Write a program that counts how many numbers in a given interval look the same after being rotated degrees. For example, the interval contains six such numbers: , , , , , and .
Input. Two integers and that define the interval to check (). You may assume the input is always valid.
Output. Print how many numbers in look the same when rotated degrees.