Problem list
Log in
#usaco0031 · USACO 2011-2012 February Silver

Cow IDs

Gold III 2.0 s 256 MB

Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, he is a bit superstitious, and only labels cows with binary numbers that have exactly K "1" bits (1 <= K <= 10). The leading bit of each label is always a "1" bit, of course. FJ assigns labels in increasing numeric order, starting from the smallest possible valid label -- a K-bit number consisting of all "1" bits. Unfortunately, he loses track of his labeling and needs your help: please determine the Nth label he should assign (1 <= N <= 10^7).

Input

Line 1: Two space-separated integers, N and K.

Output

The Nth label (in binary) that FJ should assign.

Example 1

Input
7 3
Output
10110

Input details: Among all binary numbers containing exactly 3 "1" bits, FJ wants to output the 7th in increasing sorted order.

Source
USACO 2011-2012 February Silver
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code