#B3756. Lucky Numbers in Multiple Bases

    ID: 11415 Type: Default 1000ms 256MiB

Lucky Numbers in Multiple Bases

Lucky Numbers in Multiple Bases

We say a positive integer \(n\) is a lucky number if its representations in base 5, base 7, and base 9 all do not contain the digit 0. For example:

  • \(987_{10} = (12422)_5 = (2610)_7 = (1316)_9\). Since the base 7 representation contains a 0, \(987\) is not a lucky number.
  • \(988_{10} = (12423)_5 = (2611)_7 = (1317)_9\). All representations contain no 0, so \(988\) is a lucky number.

Your task is to count how many lucky numbers are there between two given positive integers \(a\) and \(b\) (inclusive).

inputFormat

The input consists of a single line containing two space-separated integers \(a\) and \(b\) (\(a \le b\)), which specify the range in which you have to count lucky numbers.

outputFormat

Output a single integer: the count of lucky numbers between \(a\) and \(b\) (inclusive).

sample

987 988
1