Champernown constant is an irrational number represented in decimal by "0." followed by…
- User
Champernown constant is an irrational number represented in decimal by "0." followed by concatenation of all positive integers in the increasing order. The first few digits of this constant are: 0.123456789101112...
Your task is to write a program that outputs the K digits of Chapnernown constant starting at the N-th place for given two natural numbers K and N. Input
The input has multiple lines. Each line has two positive integers N and K (N ≤ 109, K ≤ 100) separated by a space.
The end of input is indicated by a line with two zeros. This line should not be processed.
Output
For each line, output a line that contains the K digits.
Example
Input
4 5 6 7 0 0
Output
45678 6789101
Assistant
pythonimport sys def find_start(N): d = 1 count = 0 while True: current_group = 9 * (10 ** (d - 1)) * d if count + current_group < N: count += current_group d += 1 else: break remaining = N - count numbers_needed = (remaining - 1) // d number = 10 ** (d - 1) + numbers_needed index_in_number = (remaining - 1) % d return number, index_in_number for line in sys.stdin: line = line.strip() if not line: continue parts = line.split() if len(parts) != 2: continue N, K = map(int, parts) if N == 0 and K == 0: break if K == 0: print('') continue number, index = find_start(N) res = [] remaining_k = K current_num = number current_idx = index while remaining_k > 0: s = str(current_num) available = len(s) - current_idx take = min(available, remaining_k) res.append(s[current_idx:current_idx + take]) remaining_k -= take if remaining_k == 0: break current_num += 1 current_idx = 0 print(''.join(res))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.