#P1384. 幸运数与排列

幸运数与排列

Description

A number is a lucky number if and only if it consists only of the digits 44 and 77, for example 4747, 744744, 47474747.

Among all permutations of 11 to nn in lexicographical order, consider the kk-th smallest permutation. Count how many indices ii such that both the position ii and the element at position ii are lucky numbers.

Input Format

One line containing two integers nn, kk.

Output Format

Output a single integer representing the answer. If the kk-th smallest permutation does not exist, output 1-1.

7 4

1
4 7

1

Hint

Sample 1 Explanation: The permutation is 1, 2, 3, 4, 6, 7, 5.

Sample 2 Explanation: The permutation is: 2, 1, 3, 4.

Constraints:

  • For 30%30\% of the testdata, it is guaranteed that n8n \le 8.
  • For 60%60\% of the testdata, it is guaranteed that n100n \le 100.
  • For 100%100\% of the testdata, it is guaranteed that 1n,k1091 \leq n, k \le 10^9.

Translated by ChatGPT 5