#B4137. Lucky Number Count

    ID: 11794 Type: Default 1000ms 256MiB

Lucky Number Count

Lucky Number Count

Given a positive integer \( n \), count how many lucky numbers there are in the range \( [1, n] \). A positive integer \( x \) is considered lucky if at least one of the following conditions holds:

  1. \( x \) is a multiple of \( 4 \);
  2. \( x \) is a multiple of \( 7 \);
  3. The string representation of \( x \) contains the substring 44 or 77.

For example, \(105\) (a multiple of \(7\)), \(442\) (contains 44), and \(1284\) (a multiple of \(4\)) are lucky numbers, while \(474\) is not.

inputFormat

The input consists of a single integer \( n \) (\(1 \le n \le 10^9\)).

outputFormat

Output a single integer representing the count of lucky numbers between \(1\) and \( n \).

sample

50
18