Problem:
 Score : 500 points    Problem Statement Let S(n) denote the sum of the digits in the decimal notation of n .
For example, S(123) = 1 + 2 + 3 = 6 .  We will call an integer n a Snuke number when, for all positive integers m such that m > n , \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.  Given an integer K , list the K smallest Snuke numbers.      Constraints  1 \leq K  The K -th smallest Snuke number is not greater than 10^{15} .         Input Input is given from Standard Input in the following format:  K       Output Print K lines. The i -th line should contain the i -th smallest Snuke number.        Sample Input 1 10      Sample Output 1 1
2
3
4
5
6
7
8
9
19

Solution (Python):
def f(num):
    s = 0
    for char in str(num):
        s += int(char)

    return num / s

K = int(input())
num = 1
power = 1
for _ in range(K):
    print(num)
    if f(num + 10 ** (power - 1)) > f(num + 10 ** power):
        power += 1
    num += 10 ** (power - 1)

Solution (Python):


def f(n):
 s=0
 for t in str(n):
  s+=int(t)
 return 1.0*int(n)/s

k=int(raw_input())
x,y=1,1
for i in xrange(k):
 print x
 if f(x+10**(y-1))>f(x+10**(y)):
  y+=1
 x+=10**(y-1)

Solution (Python):
K = int(input())

def S(n):
    return sum(int(c) for c in str(n))

n9 = 0	

count = 0
upper = 1
while count < K:
    n = int(str(upper) + ('9' * n9))
    if n <= S(n) * (10 ** n9):
        print(n)
        count += 1
        upper += 1
    else:
        n9 += 1
        upper //= 10

Solution (Python):
import math

def next_sunuke(N):
    D = math.ceil(math.log(N,10) + 1)
    z = str(N)
    zx = [int(z[:1]) for z in z]
    Z = N / sum(zx)
    ret_val = N

    ret_vals = [ret_val]
    for d in range(0, D):
        x = ( (10 ** (d + 1)) * math.floor((N / (10 ** (d+1))) + 1 ) ) - 1

        w = str(x)
        sx = [int(w[:1]) for w in w]
        y = x / sum(sx)

        if y == Z:
            Z = y
            ret_vals.append(x)
        elif y < Z:
            Z = y
            ret_vals = []
            ret_vals.append(x)
        


    return min(ret_vals)

K = int(input())
n = 1
for i in range(1,K+1):
    print(next_sunuke(n))
    n = next_sunuke(n) + 1

Solution (Python):
LEN = 0

SNK = [1,2,3,4,5,6,7,8,9]

LEN +=1

for i in range(1,10): SNK.append(i*10+9)

LEN +=1



LEN +=1

for loop in range(2):
    SNK_sub = list(range(pow(10,loop),pow(10,loop+1)))
    SNK += list(map(lambda x:(x*pow(10,LEN-1))+(pow(10,LEN-1)-1),SNK_sub))
    LEN += len(str(max(SNK_sub)))-1
    for d in SNK_sub: 
        SNK += [(i*pow(10,LEN-1))+(pow(10,LEN-1)-1) for i in range(10,10*(d+1))]
        SNK += list(map(lambda x:(x*pow(10,LEN))+(pow(10,LEN)-1),SNK_sub[SNK_sub.index(d)+1:]))
        
        LEN += 1+loop
        if LEN>20:break

print("\n".join(str(i) for i in SNK[:int(input())]))

Solution (Python):
from math import log, floor
from itertools import accumulate, chain, islice, repeat
 
k = int(input())
 
def f(n):
    ds = range(int(log(n+1, 10))+1)
    xs = [(10**(d+1))*floor(n/(10**(d+1)) + 1) - 1 for d in ds]
    return min(xs, key=lambda n:n / sum(map(int, str(n))))
 
snukes = chain(range(1, 9), accumulate(repeat(9), lambda x,_:f(x+1)))
 
for x in islice(snukes, k):
    print(x)

Solution (Python):
from math import log, floor
from itertools import accumulate, chain, islice, repeat
 
k = int(input())
 
def f(n):
    ds = range(int(log(n+1, 10))+2)
    xs = [(10**(d+1))*floor(n/(10**(d+1)) + 1) - 1 for d in ds]
    return min(xs, key=lambda n:(n / sum(map(int, str(n))), n))
 
snukes = chain(range(1, 9), accumulate(repeat(9), lambda x,_:f(x+1)))

for x in islice(snukes, k):
    print(x)

Solution (Python):
K=input()

def sunuke(m):
	a=sum( map(int,list(str(m))) )
	return float(m)/a

def f(n):
	res=n
	snk=sunuke(n)

	for keta in range(1,15):
		val=n%10
		n/=10
		for i in range(val,10):
			t=n*(10**keta)+i*(10**(keta-1))+(10**(keta-1))-1
			if sunuke(t)<snk:
				snk=sunuke(t)
				res=t
	return res


N=1
for i in range(K):
	N=f(N)
	print N
	N+=1

Solution (Python):
K=input()

def sunuke(m):
	a=sum( map(int,list(str(m))) )
	return float(m)/a

def f(n):
	res=n
	snk=sunuke(n)

	for keta in range(1,15):
		val=n%10
		n/=10
		for i in range(val,10):
			t=n*(10**keta)+i*(10**(keta-1))+(10**(keta-1))-1
			if sunuke(t)<snk:
				snk=sunuke(t)
				res=t
	return res


N=1
for i in range(K):
	N=f(N)
	print N
	N+=1

Solution (Python):
def s(n):
	return sum([ord(x)-ord('0') for x in str(n)])

def r(n):
	return n/s(n)

def f(n):
	d = 10
	m = n
	while d <= n*10:
		n //= d
		n *= d
		n += d-1
		d *= 10
		if(r(n) < r(m)):
			m = n
	return m

n = 1
for _ in range(int(input())):
	print(n)
	n = f(n+1)

Solution (Python):
def f(n):
    return n/sum(map(int,list(str(n))))
a=1
b=0
for i in range(int(input())):
    print(a)
    if f(a+10**b) > f(a+10**(b+1)):
        b+=1
    a+=10**b

Solution (Python):
def f(n):
    s, a = 0, n
    while n > 0:
        s += n % 10
        n //= 10

    return a / s


def main():
    snuke = []
    base = 1

    for i in range(15):
        for j in range(1, 140):
            snuke.append(base*(j+1)-1)
        base *= 10

    snuke.sort()
    snuke.append(0)

    snuke2 = []
    for i in range(len(snuke)-1):
        if snuke[i] != snuke[i+1]:
            snuke2.append(snuke[i])

    k, idx, t = int(input()), 0, 0
    while t < k:
        for i in range(idx+1, len(snuke2)):
            if f(snuke2[idx]) > f(snuke2[i]):
                idx += 1
                break
        else:
            print(snuke2[idx])
            t += 1
            idx += 1


if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
i=1
addNum = 1
ans = []
while(K!=0):
        print(i)
        K-=1
        S1 = 0
        S2 = 0
        for j in list(str(i+addNum)):
                S1 += int(j)
        for j in list(str(i+addNum+addNum)):
                S2 += int(j)
        if (i+addNum)/S1 > (i+addNum+addNum)/S2:
                addNum *= 10
        i += addNum

Solution (Python):
k = int(input())
def f(n):
	num,ans = n/sum([int(i) for i in str(n)]),n
	for i in range(len(str(n))+1):
		x = (10**(i+1))*(n//(10**(i+1))+1)-1
		y = x/sum([int(j) for j in str(x)])
		if num>y: ans,num = x,y
	return ans
n = 0
for _ in range(k):
	n = f(n+1)
	print(n)

Solution (Python):


K = int(input())

Sunuke = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def ns(n):
    return n / sum(map(int, list((str(n)))))


if K <= len(Sunuke):
    for i in range(K):
        print(Sunuke[i])

else:
    
    resi = K - len(Sunuke)
    
    digit = 0
    snk = 9

    while resi > 0:
        nxt1 = snk + 10**digit
        nxt2 = snk + 10**(digit+1)

        
        if ns(nxt1) > ns(nxt2):
            digit +=1
            snk = nxt2
            Sunuke.append(snk)
            resi -= 1
        else:
            snk = nxt1
            Sunuke.append(snk)
            resi -= 1


for i in range(K):
    print(Sunuke[i])

Solution (Python):
MAX = 10**15

def find_next_n(n):
    cand = []
    n_str = str(n)
    n_list = list(n_str)
    for i in range(1,len(str(n))+1):
        n_list[-i] = '9'
        cand.append(int("".join(n_list)))
    cand_result = [num/snuke(num) for num in cand]
    min_idx = cand_result.index(min(cand_result))

    return cand[min_idx]
    
    
def snuke(num):
    ans = 0
    while num//10 != 0:
        ans += num%10
        num = num//10
    return ans + num

def main():
    K = int(input())
    if K<10:
        for i in range(1,K+1):
            print(i)
    else:
        n = 10
        for i in range(1,n):
            print(i)
        for i in range(10,K+1):
            ans = find_next_n(n)
            print(ans)
            n = ans+1
            
            if n>MAX:
                break
    
    
if __name__ == "__main__":
    main()

Solution (Python):
def d_snuke_numbers(K):
    import math

    def ns(n):  
        return n / sum(map(int, list(str(n))))

    def f(n):  
        digit = len(str(n))
        
        min_ns = ns(n)
        ret = n
        for d in range(digit + 1):
            x = (10**(d+1)) * math.floor(n / (10**(d+1)) + 1) - 1
            s = ns(x)
            if min_ns > s:
                min_ns = s
                ret = x
        return ret

    n = 0
    candidate = []
    for _ in range(K):
        n = f(n + 1)
        candidate.append(n)
    ans = '\n'.join(map(str, candidate))
    return ans

K = int(input())
print(d_snuke_numbers(K))

Solution (Python):
def s(n):
    ret=0    
    for i in range(15):
        ret+=(n%10**(i+1))//10**i
    return ret

k=int(input())
ans=set()
for i in reversed(range(14)):
    m=float('inf')
    for j in reversed(range(1,1000)):
        n=int(str(j)+'9'*i)
        if n/s(n)<=m :
            ans.add(n)
            m=n/s(n)
ans=sorted(list(ans))
for a in ans[:k]:
    print(a)

Solution (Python):


k = int(input())
count = 0
ans = []
minN = 10**15

for i in reversed(range(13)):
    minN = 10**15
    for j in reversed(range(1,10**3)):
        num = str(j)+"9"*i
        n = sum([int(k) for k in num])
        n = int(num)/n
        if(minN > n or n==1):
            minN = n
            ans.append(int(num))

for i in list(sorted(list(set(ans))))[:k]:
    print(i)

Solution (Python):
K = int(input())

def S(n):
    return sum(map(int, list(str(n))))

def norm(n):
    return n/S(n)

snk = 1
order = 0
for i in range(K):
    print(snk)
    nxt1 = snk + 10 ** order
    nxt2 = snk + 10 ** (order + 1)
    if norm(nxt2) < norm(nxt1):
        order += 1
        snk = nxt2
    else:
        snk = nxt1

Solution (Python):
def nsn(n):
    s = 0
    nn = n
    while nn > 0:
        s += nn % 10
        nn = int(nn / 10)
    return n / s

def big(a):
    r = 1
    while a > 0:
        r *= 10
        a = int(a / 10)
    return r

def clear(a, d):
    aa = a
    asa = nsn(a)
    b = True
    ba = big(a)
    while aa < ba:
        aa += d
        if nsn(aa) < asa:
            b = False
            break
    return b

K = int(input())
T = [1]
a = 1
d = 1
while len(T) < K:
    n = 1
    while 1:
        an = a + n * d
        if clear(an, d):
            T.append(an)
            a = an
            d = n * d
            break
        n += 1
for x in T:
    print(x)

Solution (Python):
from math import log, floor
from itertools import islice

k = int(input())

def s(n):
    return n / sum(map(int, str(n)))

def f(n):
    ds = range(int(log(n+1, 10))+2)
    xs = [(10**(d+1))*floor(n/(10**(d+1)) + 1) - 1 for d in ds]
    return min(xs, key=s)

def g():
    for n in range(1, 10):
        yield n
    while True:
        n = f(n+1)
        yield n

for x in islice(g(), k):
    print(x)

Solution (Python):
K = int(input())

def calc(n):
    return sum(int(c) for c in str(n))

def check(n):
    for i in range(1, len(str(n))):
        p = 10**i
        m = (n // p + 1) * p - 1
        if n / calc(n) > m / calc(m):
            return False
    return True

def getlist():
    n, prev_n, d = 1, 0, 1
    while 1:
        if check(n):
            yield n
            d = n - prev_n
            prev_n = n
        n += d

from itertools import islice

for n in islice(getlist(), K):
    print(n)

Solution (Python):
K = int(input())
num = 1
pls = 1
coun = 0

while num <= 1000000000000000 and coun < K:
    while (num/sum(list(map(int, list(str(num)))))) <= ((num+pls)/sum(list(map(int, list(str(num+pls)))))) and coun < K:
        print(num)
        coun = coun + 1
        num = num + pls
    num = num - pls
    pls = pls * 10
    num = num + pls

Solution (Python):
k = int(input())
n=0
a=1
b=0
if a==1 and n<9:
    while n<9 and b<k:
        n+=1
        print(n)
        b+=1
    a+=1
if a==2:
    while n<90 and b<k:
        n+=10
        print(n)
        b+=1
    a+=1
while b<k:
    n+=10**(a-1)
    print(n)
    b+=1
    if (n>((a-1)*10**a-10**(a-1)) and a<12) or (n>((a-2)*10**a-10**(a-1)) and a>=12):
        a+=1

Solution (Python):
K = int(input())

def calc(n):
    m = 0
    while n:
        n, d = divmod(n, 10)
        m += d
    return m

def find(xs, i):
    ri, rv = None, 10**20
    for j in range(i, len(xs)):
        if xs[j] < rv:
            ri = j
            rv = xs[j]
    return ri, rv

c = 0
i = 1
prev = 0
d = 1
while 1:
    n = i
    r = 0
    k = 0
    vs = []
    while 1:
        n, m = divmod(n, 10)
        r += m
        if n == 0:
            break
        k += 1
        vs.append((n + 1) * 10**k - 1)
    if (not vs) or i / r <= min(v / calc(v) for v in vs):
        print(i)
        d = max(d, i - prev)
        prev = i
        c += 1
        if c >= K:
            break
    i += d

Solution (Python):


import math
import sys
import itertools
import numpy as np
from operator import itemgetter

k =int(input())
nmax=0
s = []
for i in range(1,200):
    for j in range(14):
        p = i
        for ii in range(j):
            p=p*10+9
        q = i // 100 + (i // 10) % 10 + i % 10 + 9*j
        r = p / q

        s.append((p,q,r))

s= sorted( s, key=itemgetter(2) )

num=0
for a in s :
    if a[0] > nmax:
        nmax = a[0]
        print(nmax)
        num += 1
        if num >= k :
            break

Solution (Python):
def digit_sum(number):
    ans = 0
    for n in str(number):
        ans += int(n)
    return ans

def obj_func(number):
    return number/digit_sum(number)

K = int(input())
num_list = []
d = 1
n = 1

for i in range(K):
    num_list.append(n)
    if obj_func(n + 10**(d-1)) > obj_func(n + 10**d):
        d += 1
    n += 10**(d-1)

print(*num_list, sep='\n')

Solution (Python):
K = int(input())


def f(n):
    s = 0
    for n_i in str(n):
        s += int(n_i)
    x = int(n) / s
    return x


order = 1
x = 1
for i in range(K):
    print(x)
    if f(x + 10 ** (order - 1)) > f(x + 10 ** (order)):
        order += 1
    x += 10 ** (order - 1)

Solution (Python):
import math
K = int(input())

def S_n(i):
    return sum(list(map(int, str(i))))

def snuke(n):
    return n / S_n(n)

j = 1
order = 1
for i in range(K):
    print(j)
    if snuke(j + 10**(order-1)) > snuke(j + 10**order):
        order += 1
    j += 10**(order-1)

Solution (Python):


def S(n):
    return sum(list(map(int, str(n))))

def norm(n):
    return n/S(n)

k = int(input())
j = 1
order = 1
for i in range(k):
    print(j)
    if norm(j+10**(order-1)) > norm(j+10**(order)):
        order += 1
    j += 10**(order-1)

Solution (Python):
def SUNUKE(i):
    x=str(i)
    SUM=0

    for j in range(len(x)):
        SUM+=int(x[j])

    return SUM,i/SUM

SUNUKESUU=[0,1,2,3,4,5,6,7,8,9]
i=10
keta=0

while i<10**16:


    if SUNUKE(i)[1]>=10**keta:
        i-=10**keta
        keta+=1
        
    else:
        if SUNUKESUU[-1]!=i:
            SUNUKESUU+=[i]
        i+=10**keta
    

for i in range(1,int(input())+1):
    print(SUNUKESUU[i])

Solution (Python):
K = int(input())
c = 0
tick = 1
i=1

while c < K:
    s = sum(map(int,list(str(i))))
    if s*tick<i:
        i += 9*tick
        tick*=10
    else:
        print(i)
        c+=1
        i+=tick

Solution (Python):
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp
import itertools as it
import functools
import math

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

K = ri()

@functools.lru_cache()
def Sx(i):
  return i/sum(int(s) for s in str(i))

def gen():
  diff = 1
  n = 1
  while True:
    if Sx(n) <= Sx(n+diff):
      yield n
      n += diff
    else:
      n -= diff
      diff *= 10
      n += diff

for n in it.islice(gen(),K):
  print(n)

Solution (Python):
k = int(input())




def s(n):
    return sum(list(map(int, str(n))))

seeds = [i for i in range(1, 10)]
for i in range(15):
    for j in range(10):
        for m in range(10):
            for y in range(10):
                seeds.append(int(str(m + j*10 + y*100) + str(9)*i))



seeds = [i for i in seeds if i!=0]

l = []
for i in seeds:
    l.append([i, s(i), i/s(i)])





l.sort(key=lambda x:x[2])



max = 0
ans = []
for i in range(len(l)):
    if l[i][0] > max:
        max = l[i][0]
        ans.append(l[i][0])
        

for i in range(k):
    print(ans[i])

Solution (Python):
K = int(input())

def S(n):
    m = n
    s = 0
    while m > 0:
        s  += m % 10
        m //= 10
    return s


n9 = 0
e = 10 ** n9

count = 0
upper = 1
while count < K:
    n = (upper + 1) * e - 1
    s = S(upper) + 9 * n9
    if n <= e * s:
        print(n)
        upper += 1
        count += 1
    else:
        n9 += 1
        e  *= 10
        upper //= 10

Solution (Python):
def S(n):
    num = 0
    for c in str(n):
        num += int(c)
    return num

def norm(n):
    return n / S(n)

k = int(input())
j = 1
order = 1
for i in range(k):
    print(j) 
    if norm(j + 10 ** (order - 1)) > norm(j + 10 ** (order)):
        order += 1
    j += 10 ** (order - 1)