P16173 [GeeksforGeeks] Construct binary palindrome by repeated appending and trimming1005
普及
题目描述

Given n and k, Construct a palindrome of size n using the binary representation of the number k.To construct the palindrome you can use the binary number of size k as many times as you wish and also you can trim all the zeros from the end.The palindrome must always begin with 1 and contains the maximum number of zeros.

Example 1 :
Input : n = 5, k = 6
Output : 11011
Explanation: Binary representation of 6 is
110.After combining 110
twice and trimming the extra 0 in
the end we get 11011
Example 2:
Input: n = 5, k = 8
Output: 10001
Explanation: Binary representation of 8 is
1000.After combining 1000 twice and trimming
the extra 0 in the end we get 10001.
Your Task:
You don't need to read or print anything. Your task is to complete the function binaryPalindrome() that takes two integers n, k and return a string of size n.
Expected Time Complexity: O(n).
Expected Auxiliary Space: O(1).
Constraints:
1 ≤ n ≤ 10^{5}
1 ≤ k ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
n = 5, k = 6
样例输出
11011