#P1384. 幸运数与排列

    ID: 2190 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学福建省历届夏令营

幸运数与排列

Problem 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