Problem:


Problem C:Champernowne Constant

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.

Sample Input

4 5
6 7
0 0

Output for the Sample Input

45678
6789101



Sample input:
4 5
6 7
0 0


Sample output:
45678
6789101

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f(n,m):
        n -= 1
        i = 1
        l = 1
        for k in range(1,10):
            if n > 10**(k-1) * 9 * k:
                n -= 10**(k-1) * 9 * k
                i = 10 ** k
                l = k
            else:
                break
        i += n // l
        n %= l
        r = ''
        for j in range(i,i+101):
            r += str(j)
        return r[n:n+m]

    while True:
        n,m = LI()
        if n == 0 and m == 0:
            break
        rr.append(f(n,m))

    return '\n'.join(map(str,rr))


print(main())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import math
while True:
    a,b = map(int,raw_input().split(' '))
    if (a == 0 and b == 0):
        sys.exit()
    res = ""
    for i in range(a,a+b):
        res += str(i);
    ans = ""
    for i in range(a,a+b):
        ans+=res[i-a]
    print ans

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f(n,m):
        n -= 1
        i = 1
        l = 1
        for k in range(1,10):
            if n > 10**(k-1) * 9 * k:
                n -= 10**(k-1) * 9 * k
                i = 10 ** k
                l = k + 1
            else:
                break
        i += n // l
        n %= l
        r = ''
        for j in range(i,i+101):
            r += str(j)
        return r[n:n+m]

    while True:
        n,m = LI()
        if n == 0 and m == 0:
            break
        rr.append(f(n,m))

    return '\n'.join(map(str,rr))


print(main())

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

def d_num(num):
    ret = 0
    s = str(num)
    d = len(s)
    if d == 1:
        return num
    for i in range(d - 1):
        ret += (i + 1) * 9 * 10 ** i
    return ret + d * (num - 10 ** (d - 1) + 1)

def search(num, l, r):
    if r - l <= 1:
        return l, num - d_num(l)
    mid = (l + r) / 2
    if d_num(mid) > num:
        r = mid
    else:
        l = mid
    return search(num, l, r)

while True:
    K, N = map(int, raw_input().split())
    if K == 0:
        break
    '''
    S = ''
    for i in range(10000):
        S += str(i)
    print S[K:K + N]
    '''
    p = search(K - 1, 0, 10 ** 18)

    S = ''
    for i in range(p[0] + 1, p[0] + 101):
        S += str(i)
    print S[p[1]:p[1] + N]

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

def d_num(num):
    ret = 0
    d = len(str(num))
    for i in range(d - 1):
        ret += (i + 1) * 9 * 10 ** i
    return ret + d * (num - 10 ** (d - 1) + 1)

def search(num, l, r):
    if r - l <= 1:
        return l, num - d_num(l)
    mid = (l + r) / 2
    if d_num(mid) > num:
        r = mid
    else:
        l = mid
    return search(num, l, r)

while True:
    K, N = map(int, raw_input().split())
    if K == 0:
        break

    p = search(K - 1, 0, 10 ** 18)
    S = ''
    for i in range(p[0] + 1, p[0] + 101):
        S += str(i)
    print S[p[1]:p[1] + N]

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    li = list("ixcm")
    k = [1,10,100,1000]
    d = {"i":1,"x":10,"c":100,"m":1000}
    f = ["i","x","c","m"]
    for _ in range(n):
        a,b = LS()
        s = 0
        for i in range(len(a)):
            if a[i] in li:
                a[i] = d[a[i]]
                if i > 0 and a[i-1] not in k:
                    s += a[i-1]*a[i]
                else:
                    s += a[i]
            else:
                a[i] = int(a[i])

        for i in range(len(b)):
            if b[i] in li:
                b[i] = d[b[i]]
                if i > 0 and b[i-1] not in k:
                    s += b[i-1]*b[i]
                else:
                    s += b[i]

            else:
                b[i] = int(b[i])
        ans = []
        while s != 0:
            i = int(math.log(s+0.1,10))
            m = s//k[i]
            s %= k[i]
            if m != 1:
                ans.append(m)
            ans.append(f[i])
        for i in ans:
            print(i,end="")
        print()
    return

#B
def B():
    d = [(0,1),(0,-1),(1,0),(-1,0),(1,1),(-1,-1)]
    while 1:
        t,n = LI()
        if t == n == 0:
            break
        f = defaultdict(lambda : 1)
        for i in range(n):
            x,y = LI()
            f[(x,y)] = 0
        x,y = LI()
        bfs = defaultdict(lambda : 1)
        q = deque()
        q.append((x,y,0))
        bfs[(x,y)] = 0
        ans = 1
        while q:
            x,y,turn = q.popleft()
            if turn < t:
                for dx,dy in d:
                    x2 = x+dx
                    y2 = y+dy
                    if bfs[(x2,y2)]:
                        if f[(x2,y2)]:
                            ans += 1
                            bfs[(x2,y2)] = 0
                            q.append((x2,y2,turn+1))
        print(ans)
    return

#C
def C():
    return

#D
def D():
    def f(n):
        if d[n] != None:
            return d[n]
        else:
            i = int(math.log(n+0.1,10))
            d[n] = d[10**i]
            m = n-10**i
            d[n] += (i+1)*m
            return d[n]
    lis = [1]
    for i in range(10):
        lis.append(lis[-1]+(i+1)*9*10**i)
    d = defaultdict(lambda : None)
    for i in range(11):
        d[10**i] = lis[i]

    while 1:
        n,k = LI()
        if n == k == 0:
            break
        l = 0
        r = 1000000000
        while r-l > 1:
            m = (r+l)//2
            if n < f(m):
                r = m
            else:
                l = m
        s = str(l)[n-f(l):]
        n = l
        while len(s) <= k:
            k -= len(s)
            print(s,end="")
            n += 1
            s = str(n)
        print(s[:k])
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import math
while True:
#    a,b = map(int,raw_input().split(' '))
    a = int(raw_input())
    b = int(raw_input())
    if (a == 0 and b == 0):
        sys.exit()
    res = ""
    for i in range(a,a+b):
        res += str(i);
    ans = ""
    for i in range(a,a+b):
        ans+=res[i-a]
    print ans

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import math
while True:
    a,b = map(int,raw_input().split(' '))
    if (a == 0 and b == 0):
        sys.exit()
    res = ""
    for i in range(a,min(a+b,100/len(str(a)))):
        res += str(i);
    ans = ""
    for i in range(a,a+b):
        ans+=res[i-a]
    print ans