CCC '00 J2 - 9966

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2000 Stage 1, Junior #2

The digits 0, 1, and 8 look much the same if rotated 180 degrees on the page (turned upside down). Also, the digit 6 looks much like a 9, and vice versa, when rotated 180 degrees on the page. A multi-digit number may also look like itself when rotated on the page; for example 9966 and 10\,801 do, but 999 and 1234 do not.

You are to write a program to count how many numbers from a given interval look like themselves when rotated 180 degrees on the page. For example, in the interval [1 \dots 100] there are six: 1, 8, 11, 69, 88, and 96.

Your program should take as input two integers, m and n, which define the interval to be checked, 1 \le m \le n \le 32\,000. The output from your program is the number of rotatable numbers in the interval.

You may assume that all input is valid.

Sample Input

1
100

Sample Output

6

Comments


  • 0
    837830  commented on Dec. 31, 2025, 7:41 p.m.

    Here are all of the number between 1 and 32,000:

    numbers = [1, 8, 11, 69, 88, 96, 101, 111, 181, 609, 619, 689, 808, 818, 888, 906, 916, 986, 1001, 1111, 1691, 1881, 1961, 6009, 6119, 6699, 6889, 6969, 8008, 8118, 8698, 8888, 8968, 9006, 9116, 9696, 9886, 9966, 10001, 10101, 10801, 11011, 11111, 11811, 16091, 16191, 16891, 18081, 18181, 18881, 19061, 19161, 19861]


  • 0
    MonkeyKang16  commented on Sept. 6, 2025, 4:48 p.m.

    for this its a good idea to use min and max to convert your 2 varibles like this for example
    your varible name here = min(n, m)
    your other varible name here = max(n, m)


  • 2
    d  commented on June 8, 2025, 11:18 p.m.

    Sequence for this problem https://oeis.org/A000787