#P8764. [蓝桥杯 2021 国 BC] 二进制问题

    ID: 9682 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2021数位 DP蓝桥杯国赛

[蓝桥杯 2021 国 BC] 二进制问题

Problem Description

Xiaolan has been learning binary recently. He wants to know how many numbers from 11 to NN have exactly KK 1s in their binary representation. Can you help him?

Input Format

Input one line containing two integers NN and KK.

Output Format

Output one integer representing the answer.

7 2
3

Hint

For 30%30\% of the testdata, 1N106,1K101 \leq N \leq 10^{6}, 1 \leq K \leq 10.

For 60%60\% of the testdata, 1N2×109,1K301 \leq N \leq 2 \times 10^{9}, 1 \leq K \leq 30.

For all testdata, 1N1018,1K501 \leq N \leq 10^{18}, 1 \leq K \leq 50.

Lanqiao Cup 2021 National Contest, Group B Problem H (Group C Problem J).

Translated by ChatGPT 5