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



Sample input:
10


Sample output:
1
2
3
4
5
6
7
8
9
19

Submission status: Accepted

Solution code:
def s(n):
    ret = 0
    while n > 0:
        ret += n % 10
        n //= 10
    return ret

numbers = [999999999999999999]
while numbers[-1] > 1:
    for d in range(0, 100):
        n = numbers[-1]
        m = n - 10 ** d
        if n * s(m) >= m * s(n):
            numbers.append(m)
            break
numbers = list(reversed(numbers))

n = int(input())
for i in range(n):
    print(numbers[i])

Submission status: Accepted

Solution code:
def snu(n):
    s=str(n)
    kei=sum(int(x) for x in s)
    return n/kei

def nn(n):
    s=str(n)
    kt=len(str(int(snu(n))))
    if s[-kt:].count("9")==kt:
        if s[-kt-1]=="9":
            n+=10**kt
            s=str(n)
            kt = len(str(int(snu(n))))
            if s[-kt:].count("9") == kt:
                return n
            else:
                s = s[:-kt] + "9" * kt
                return int(s)
        else:
            return n+10**kt
    else:
        s=s[:-kt]+"9"*kt
        return int(s)

k=int(input())
t=9 if k>9 else k
for i in range(1,t+1):
    print(i)
if k<=9:exit()
n=19
for _ in range(k-9):
    print(n)
    n=nn(n)

Submission status: Accepted

Solution code:
K = int(input())

def minSunuke(n) :  # n以上の n/S(n) の最小値
    sumDigit = sum(map(int, list(str(n))))
    return n / sumDigit

digit = 0
now = 1

for i in range(K) :
    print(now)
    if minSunuke(now + 10**digit) > minSunuke(now + 10**(digit + 1)) :
        digit += 1
    now += 10**digit

Submission status: Accepted

Solution code:
def digit_sum(n):
    res = 0
    while n > 0:
        res += n % 10
        n /= 10
    return res
k = int(raw_input())
snuke_num = 1
num_of_nums = 0
increment = 1
while num_of_nums < k:
    print snuke_num
    num_of_nums += 1
    candid = snuke_num + increment
    opponent = candid + increment
    if float(candid)/digit_sum(candid) > float(opponent) / digit_sum(opponent):
        increment *= 10
    snuke_num += increment

Submission status: Accepted

Solution code:
k=int(input())
def s(n):
    m=str(n)
    l=list(m)
    l=map(int,l)
    return n/sum(l)
p=1
q=0
for i in range(k):
    print(p)
    if s(p+10**q)>s(p+10**(q+1)):
        q+=1
    p+=10**q

Submission status: Accepted

Solution code:
K=int(input())
n=1
k=0
x=[]
y=x.append
while(n<=10**15):
    plus=10**k
    if n>=1350*plus:
        n+=9*plus
        k+=1
        plus*=10
    y([n,n/sum(map(int,list(str(n))))])
    n+=plus
x2=[]
y2=x2.append
min_=10**15
for i in range(len(x)-1,-1,-1):
    if x[i][1]<=min_:
        y2(x[i][0])
        min_=x[i][1]
x2=list(reversed(x2))
for i in range(K):
    print(x2[i])

Submission status: Accepted

Solution code:
def digitsum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

def list_to_num(l):
    s = 0
    for i in range(len(l)):
        s += l[i]*pow(10,i)
    return s

k = int(input())

def func(a):
    n = a+1
    if a == 0:
        return 1
    elif n/digitsum(n)==1:
        return n
    else:
        s = str(n)
        array = list(map(int, s))[::-1]
        if len(list(set(array)))==1 and list(set(array))[0]==9:
            n =list_to_num(array)+1
            s = str(n)
            array = list(map(int, s))[::-1]
        min = pow(10,15)
        ans = 0
        for i in range(len(array)):
            for j in range(array[i]+1,10):
                array[i] = j
                temp = list_to_num(array)/digitsum(list_to_num(array))
                if temp < min:
                    min = temp
                    ans = list_to_num(array)
        return ans


n = 0
for i in range(k):
    print(func(n))
    n = func(n)

Submission status: Accepted

Solution code:
K=int(input())
tmp=0
i=0
k=0
res=1
def S(a):
  res=0
  while(a!=0):
    res+=a%10
    a//=10
  return res
def check(i,a):
  if (10**i)*S(a)<a:
    return True
  return False
while(True):
  if k==K:
    break
  print(res)
  k+=1
  res+=10**i
  if check(i,res):
    res-=10**i
    i+=1
    res+=10**i

Submission status: Accepted

Solution code:
# 下d+1桁目が初めて9でないとする
# [__X__]99999
# [_X++_]99999に勝つ必要がある
# 10^d(X+1)-1 / (S(X) + 9d) <= (10^d(X+2)-1) / (S(X)+9d+1)
# (S(X)+9d+1)/(S(X)+9d) <= (10^d(X+2)-1)/(10^d(X+1)-1)
# 1/(S(X)+9d) <= 10^d / (10^d(X+1)-1) <= 1/X
# X <= S(X)+9d <= 135

def S(n):
  if n < 10:
    return n
  return S(n//10) + n%10
  
li = [] # 候補、とりあえず十分量作る

for d in range(20):
  a = 10**d
  for x in range(200):
    y = (x+1)*a-1
    if y > 0:
      z = S(y)
      li.append((y,z))
    
li = sorted(list(set(li)),reverse=True)

# 右から見ていって、その時点での最小値タイ以下なら採用
answer = []
min_N,min_S = li[0]
for n,s in li[1:]:
  # n/s < min_N/min_S
  if n*min_S <= s*min_N:
    min_N = n
    min_S = s
    answer.append(n)


K = int(input())
answer.sort()
answer = answer[:K]
print('\n'.join(map(str,answer)))

Submission status: Accepted

Solution code:
k = int(input())
candili = []
for i in range(1, 1000):
    candili.append(i)

tmpli = []
for i in candili:
    for j in range(1, 15):
        tmpli.append(int(str(i) + "9" * j))
tmpli = list(set(tmpli))

tmp2li = []
for i in tmpli:
    if i <= 10 ** 15:
        tmp2li.append(i)
candili += tmp2li
candili = list(set(candili))
candili.sort()

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

conli = []

for i in candili:
    conli.append(i/S(i))

ansli = []
for i in range(len(conli)):
    for j in range(i, len(conli)):
        if conli[i] > conli[j]:
            break
    else:
        ansli.append(candili[i])

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

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


k = 0

def print_ans(x):
    global k
    print(x)
    k -= 1
    if k <= 0:
        exit(0)
    return x


def s(n):
    ret = 0
    while n:
        ret += n % 10
        n = n // 10
    return ret


def get_anslist(base, msnum, pownum):
    do_break = False
    end = ((msnum + 10) // 10) * 10
    ret = []

    for i in range(msnum, end):
        m = base + i * (10**pownum)
        snuke = m / s(m)
        ret.append((m, snuke))
        if snuke >= (10**pownum):
            do_break = True
    return ret, do_break


def main():
    global k
    k = intin()
    max_print = -1

    for i in range(16):
        base = 0 if i == 0 else int('9' * i)
        msnum = 1
        if max_print >= base:
            msnum = (max_print - base) // (10**i) + 1
        anslist = []

        while True:
            part_anslist, do_break = get_anslist(base, msnum, i)
            anslist.append(part_anslist)
            if do_break:
                break
            msnum = ((msnum + 10) // 10) * 10

        for part_anslist in anslist:
            prev = None
            incr = True
            for ans, snuke in part_anslist:
                if prev is not None and snuke < prev:
                    incr = False
                prev = last = snuke
            if incr:
                for ans, snuke in part_anslist:
                    max_print = print_ans(ans)
            else:
                prev = None
                for ans, snuke in part_anslist:
                    if snuke <= last:
                        max_print = print_ans(ans)
                    if prev is not None and prev > snuke:
                        break
                    prev = snuke


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def funuke(now):
    count = 0
    for ele in list(str(now)):
        count += int(ele)
    return now / count

def main():
    num = int(input())

    keta = 1
    now = 1
    count = 0

    while count < num:
        if funuke(now) <= funuke(now + keta):
            count += 1
            print(now)
            now += keta
        else:
            now += 9 * keta
            keta *= 10

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#D問題
K=int(input())
keta=1
now=1
count=0

def sunuke(n):
    a=0
    for i in str(n):
        a+=int(i)
    return(n/a)

while count < K:
    if sunuke(now) <= sunuke(now+keta):
        print(now)
        now+=keta
        count+=1
    else:
        now+=9*keta
        keta*=10

Submission status: Accepted

Solution code:
K = int(input())
 
def f(n):
    return n / sum([int(s) for s in str(n)])

ans = [1]
for k in range(K - 1):
    min_f_val, next_snuke = float('inf'), None
    n = str(ans[-1] + 1)
    for i in range(len(n)):
        for x in range(int(n[i]), 10):
            X = n[:i] + str(x) + '9' * (len(n) - i - 1)
            f_val = f(int(X))
            if f_val < min_f_val:
                next_snuke = int(X)
                min_f_val = f_val
    ans.append(next_snuke)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
k = int(input())
keta = 1
ima = 1
def sunuke(n) :
    a = 0
    for i in str(n) :
        a += int(i)
    return(n/a)
count = 0
while count < k :
    if sunuke(ima) <= sunuke(ima+keta) :
        print(ima)
        ima += keta
        count += 1
    else :
        ima += 9*keta
        keta *= 10

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log10
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

K = INT()

def S(n): # 和,nは文字列
	return sum([int(x) for x in list(n)])

def f(N):
	sunuke = []
	for d in range(-1, int(log10(N)+1)):
		sunuke.append(10**(d+1) * (N//(10**(d+1))+1)-1)
	sunuke2 = [x/S(str(x)) for x in sunuke]
	return sunuke[sunuke2.index(min(sunuke2))]

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

Submission status: Accepted

Solution code:
K = int(input())


def f(n):
    return n / sum([int(s) for s in str(n)])


ans = [1]
for k in range(K - 1):
    min_f_val, next_snuke = float('inf'), None
    n = str(ans[-1] + 1)

    for i in range(len(n)):
        for x in range(int(n[i]), 10):
            X = n[:i] + str(x) + '9' * (len(n) - i - 1)
            f_val = f(int(X))

            if f_val < min_f_val:
                next_snuke = int(X)
                min_f_val = f_val

    ans.append(next_snuke)

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

Submission status: Accepted

Solution code:
K = int(input())

#すぬけ数候補
# [n, S(n)/n] で覚える
snukePairs = []

for i in range(1, 16):
    top = 1  #上位何桁を1-9の走査範囲とするか
    if i >= 12:
        top = 3
    elif i >= 4:
        top = 2
    p = pow(10, i - top)
    fill9 = p - 1
    top_num = pow(10, max(top, 1)) #たかが1000。全部回す
    check_index = len(snukePairs)
    for j in range(pow(10, top - 1), top_num):
        num = j * p + fill9
        nn = num
        s = 0
        #各桁合計、 S(n) / n 計算
        while nn > 0:
            s += nn % 10
            nn = nn // 10
        val = num / s

        #既存のもののうち、valより小さいものを除外
        idx = len(snukePairs) - 1
        while idx >= 0:
            if snukePairs[idx][1] > val:
                del snukePairs[idx]
            idx -= 1
        snukePairs.append([num, val])

for i in range(0, K):
    print(snukePairs[i][0])

Submission status: Accepted

Solution code:
def cal(n):
    m = n
    ret = 0
    while n != 0:
        ret += n % 10
        n //= 10
    return m/ret

# n以上で s(n) が最小となる整数値
def f(n):
    cand = []
    s = str(n)
    for i in range(len(s)-1,-1,-1):
        if s[i] == "9":
            continue
        for j in range(int(s[i]), 10):
            t = int(s[:i] + str(j) + s[i+1:])
            cand += [ t ]
        s = s[:i] + "9" + s[i+1:]

    ret = n
    for x in cand:
        if cal(x) < cal(ret):
            ret = x
    return ret 


k = int(input())
ans = 1

for _ in range(k):
    print(ans)
    ans = f(ans+1)

Submission status: Accepted

Solution code:
k = int(input())

def f(num):
  return num / sum(map(int, list(str(num))))

order = 0
sunuke = 1
for i in range(k):
  print(sunuke)
  sunuke += 10**order
  if f(sunuke + 10**(order+1)) < f(sunuke + 10**order):
    order += 1

Submission status: Accepted

Solution code:
k = int(input())

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

def find_next(n):
    d = 0
    m = n // 10
    sm = s(m)
    r = 0
    grad = 10 * m + 1 - sm - 9 * d - 1/(10**d)
    while grad > 0:
        r += 9 * 10**d
        d += 1
        sm -= m % 10
        m = m // 10
        grad = 10 * m + 1 - sm - 9 * d - 1/(10**d)
    r += (n // 10**d) * 10**d
    return r

for i in range(1, min(k, 9) + 1):
    print(i)
    
k -= min(k, 9)
p = 10

for i in range(0, k):
    p = find_next(p)
    print(p)
    p += 1

Submission status: Accepted

Solution code:
k = int(input())

cnt = 0
step = 1
base = 1
tail = ""
now = 0
def f(x):
    s = list(str(x))
    return sum([int(i) for i in s])
while 1:
    now += step
    if now > step*f(now):
        now -= step
        step *= 10
    else:
        cnt += 1
        print(now)
        if cnt == k:
            exit(0)

Submission status: Accepted

Solution code:
k = int(input())

def func(a):
    s = 0
    for i in str(a):
        s += int(i)
    return a/s

candidate_lst = []
for i in range(18):
    for j in range(1, 150):
         candidate_lst.append(int(str(j) + '9' * i))
candidate_lst = sorted(list(set(candidate_lst)))

count = 0
index = -1
snuke = 1
while count < k:
    min_snuke = 10**100
    for m, i in enumerate(candidate_lst[index+1:]):
        if i > 100*snuke:
            break
        po_snuke = func(i)
        if min_snuke > po_snuke:
            min_snuke = po_snuke
            next_snuke = i
            next_index = m
    print(next_snuke)
    snuke = next_snuke
    index = index + next_index + 1
    count += 1

Submission status: Accepted

Solution code:
k = int(input())

def snuke(n):
    def func(a):
        s = 0
        for i in str(a):
            s += int(i)
        return a/s
    
    len_n = len(str(n))
    min_snu = 10 ** 100
    for i in range(len_n):
        snu = str(n)[:len_n-i] + i * '9'
        func_snu = func(int(snu))
        if min_snu > func_snu:
            min_snu = func_snu
            snukee = int(snu)
            
    return snukee

count = 0
n = 1
while count < k:
    next_snuke = snuke(n)
    print(next_snuke)
    n = next_snuke + 1
    count += 1

Submission status: Accepted

Solution code:
from math import log10, ceil


def S(n: int) -> int:
    """n を十進法で表した時の各桁のあたいの総和
    :param n: 任意の正の整数
    :return: 十進法の各桁の和
    """
    s = 0
    while n > 0:
        s += n % 10
        n //= 10
    return s


def f(N: int) -> int:
    if N < 10:
        return N

    D = ceil(log10(N) + 1)
    x = 10 * (N // 10 + 1) - 1
    for d in range(1, D + 1):
        td = 10 ** (d + 1)
        nx = td * (N // td + 1) - 1

        if nx / S(nx) < x / S(x):
            x = nx
    return x


if __name__ == "__main__":
    K = int(input())
    N = 1
    for _ in range(K):
        print(N)
        N = f(N+1)

Submission status: Accepted

Solution code:
inf = 1 << 60
m = inf
i = 10 ** 15 - 1
sunuke = []
while i > 0:
    a=sum(map(int,str(i)))
    b=i/a
    if m >= b:
        #print(f'{i} / {a} = {b}')
        m = b
        sunuke.append(i)
    for j in range(15,2,-1):
        if i > 10**j:
            i -= 10**(j-3)
            break
    else:
        i -= 1

K=int(input())
for i in range(K):
    print(sunuke[-i-1])

Submission status: Accepted

Solution code:
t = i = 1
k = int(input()) 
while k:
  if t < i / sum(map(int, list(str(i)))):
    i += 9 * t
    t *= 10
  else:
    print(i)
    i += t
    k -= 1

Submission status: Accepted

Solution code:
t = i = 1
k = int(input()) 
while k:
  if t < i / sum(map(int, list(str(i)))):
    i += 9 * t
    t *= 10
  else:
    print(i)
    i += t
    k -= 1

Submission status: Accepted

Solution code:
import sys
K = int(input())
count = 0
nine = ""

arr = []
arr_sunuke = []
for k in range(14):
    for i in range(10):
        for j in range(10):
            for l in range(10):
                if i == 0 and nine != "":
                    pass
                else:
                    arr.append(int(str(i)+str(j)+str(l)+nine))
                    arr_sunuke.append(i + j + l + k*9)
    nine = nine + str(9)

arr.remove(0)
arr_sunuke.remove(0)
arr_sunuke2 = [arr[i]/arr_sunuke[i] for i in range(len(arr))]

ans = []
tmp = 10**15
for i in range(len(arr)-1, -1, -1):
    if arr_sunuke2[i] <= tmp:
        ans.append(arr[i])
        tmp = arr_sunuke2[i]

ans = ans[::-1]
for i in range(K):
    print(ans[i])

Submission status: Accepted

Solution code:
import sys

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


def f(n):
  d = 0
  C = [n]
  while S(n) > (10**d / 9*(d+1)):
    c = 10**(d+1) * (n // 10**(d+1) + 1) - 1
    C.append(c)
    d += 1
  Smin = float('inf')
  res = 0
  for c in C:
    if S(c) < Smin:
      Smin = S(c)
      res = c  
  return res


def main():
  input = sys.stdin.readline
  K = int(input())
  ans = 1
  for _ in range(K):
    print(ans)
    ans = f(ans+1)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
K = int(input())
n = 1
dn = 1
c = 0
while c < K:
    print(n)
    c += 1
    if (n + dn) > sum(map(int, str(n + dn))) * dn:
        dn *= 10
    n += dn

Submission status: Accepted

Solution code:
serch_table = []

for i in range(100):
    for j in range(1,1000):
        x = str(j) + '9'*i
        x = int(x)
        serch_table.append(x)
#print(serch_table)

L = []
for i in serch_table:
    l = [x for x in str(i)]
    x = sum(map(int,l))
    l = [i/x,i]
    L.append(l)
L= sorted(L)
M = []
tmp = -1
for i in L:
    if tmp < i[1]:
        M.append(i[1])
        tmp = i[1]
#print(M,len(serch_table ))
N = int(input())
for i in range(N):
    print(M[i])

Submission status: Accepted

Solution code:
K = int(input())


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


def g(n):
    return n / dsum(n)

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

Submission status: Accepted

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

def main():
    K = int(input())

    l = []
    for i in range(1, 1000):
        l.append(i)
    for k in range(1, 13):
        n0 = 10 ** k
        for i in range(100, 1000):
            l.append(i * n0 + n0 - 1)

    r = []
    for n in l:
        sn = 0
        d = n
        while 0 < d:
            d, m = int(d / 10), d % 10
            sn += m
        r.append(n / sn)

    min_r = r[-1]
    for i in range(len(r) - 2, -1, -1):
        if min_r < r[i]:
            r.pop(i)
            l.pop(i)
        else:
            min_r = r[i]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())

def digit_sum(s):
    return sum(map(int, list(s)))

def func1(s):
    return int(s)/digit_sum(s)

def func2(n):
    n = str(n)
    fm, fa = float("inf"), -1
    for i in range(len(n)):
        s = n[:i+1] + "9"*(len(n)-i-1)
        if fm > func1(s):
            fm = func1(s)
            fa = int(s)
    return fa

n = 1
for _ in range(k):
    print(n)
    n = func2(n+1)

Submission status: Accepted

Solution code:
from collections import deque
k = int(input())

digsum = lambda x: sum(map(int, list(str(x))))
dignorm = lambda x: x/digsum(x)

n = 1
order = 1
while k > 0:
    print(n)
    k -= 1
    if dignorm(n+10**(order-1)) > dignorm(n+10**order):
        order += 1
    n += 10**(order-1)

Submission status: Accepted

Solution code:
K = int(input())


def digit_sum(s):
    return sum([int(i) for i in str(s)])


def f(n):
    n = str(n)
    f_min, f_ans = float('inf'), -1
    for i in range(len(n)):  # 上から何桁目をいじるか
        for x in range(int(n[i]), 10):
            s = n[:i] + str(x) + '9' * (len(n) - i - 1)
            if f_min > int(s) / digit_sum(s):
                f_min = int(s) / digit_sum(s)
                f_ans = int(s)
    return f_ans


ans = [1]
for k in range(K - 1):
    ans.append(f(ans[-1] + 1))

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

Submission status: Accepted

Solution code:
k = int(input())
sunuke_list = [1,2,3,4,5,6,7,8]
def s(n):
    n_charlist = list(str(n))
    return sum(list(map(int, n_charlist)))
def combine_int(i,n):
    i_charlist = list(str(i))
    n_charlist = ['9'] * n
    ret_charlist = i_charlist + n_charlist
    ret_str = ''.join(ret_charlist)
    return int(ret_str)
for n in range(1,14):
    if n >= 12:
        i = n-2
    else:
        i = n-1
    while((i+1)/(s(i)+9*n) <= (i+2)/(s(i+1)+9*n)):
        sunuke_list.append(combine_int(i,n))
        i += 1
for i in range(k):
    print(sunuke_list[i])

Submission status: Accepted

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

"""
参考：https://nuekodory.github.io/2018/06/24/AtCoder-ABC101-ARC-099-%E3%82%92-Python3-%E3%81%A7%E8%A7%A3%E3%81%8F/
　　　http://xxxasdfghjk999.hatenablog.jp/entry/2018/07/22/162323
　　　http://drken1215.hatenablog.com/entry/2018/06/24/010600
　　　http://phyllo-algo.hatenablog.com/entry/2018/06/24/160442
・事前にいくつかの範囲を調べて、候補の数がabc9999....のあたりだけだと予測しておく。
・候補の値だけに絞って最大値から下がっていく。
"""

K = int(input())

def make_snk(num):
    s = str(num)
    sm = 0
    for c in s:
        sm += int(c)
    return num / sm

snk_list = []
mn = float('inf')
suff = '999999999999'
# 後ろに付ける9の数を減らして、10^15-1から10099までを作る
for i in range(11):
    # 999～100までループ
    for j in range(999, 99, -1):
        j = int(str(j) + suff)
        num = make_snk(j)
        if num <= mn:
            snk_list.append(j)
            mn = num
    suff = suff[:-1]
# 9999以下は普通に全部やる(大した大きさじゃないので)
for i in range(9999, 0, -1):
    num = make_snk(i)
    if num <= mn:
        snk_list.append(i)
        mn = num
snk_list.reverse()
for i in range(K):
    print(snk_list[i])

Submission status: Accepted

Solution code:
from math import log10 as l
s=lambda f:sum(map(int,list(str(f))))
p=lambda a,j:(a//10**(j+1)+1)*10**(j+1)-1
n=int(input())
a=1
for i in range(n):
  print(a)
  if(a<9):
    a+=1
    continue
  a+=1
  k=[p(a,j) for j in range(int(l(a)))]
  o=[p(a,j)/s(p(a,j)) for j in range(int(l(a)))]
  a=k[o.index(min(o))]

Submission status: Accepted

Solution code:
import math
K=int(input())
k=2
m=0
def D(x):
  s=str(x)
  array=list(map(int,list(s)))
  return sum(array)
N=1
S=1
a=0
print(1)
while k<=K:
  N+=10**a
  S=D(N)
  if a<math.log10(N/S):
    a+=1
    N=(N//10**a+1)*10**a-1
  S=D(N)
  print(N)
  k+=1

Submission status: Accepted

Solution code:
def f(n):
    return n/sum(map(int,str(n)))

K = int(input())
x = 1
p = 0 
for k in range(K):
    print(x)
    if f(x+10**p) > f(x+10**(p+1)):
        p += 1
    x += 10**p

Submission status: Accepted

Solution code:
from collections import deque
k = int(input())

digsum = lambda x: sum(list(map(int, list(str(x)))))
dignorm = lambda x: x/digsum(x)

n = 1
order = 1
while k > 0:
    print(n)
    k -= 1
    if dignorm(n+10**(order-1)) > dignorm(n+10**order):
        order += 1
    n += 10**(order-1)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def ds(n:int):
    return sum([int(i) for i in str(n)])

def snuke(n:int):
    return n/ds(n)

def cands(n:int):
    ret = []
    nl = len(str(n))
    for i in range(nl):
        ret.append(str(n)[:nl-i-1] + "9"*(i+1))
        
    return ret

k = ni()

# 1から9まで
ans = [i for i in range(1,10)]

# 次の候補
cur = 10
while len(ans) < k:
    cand = cands(cur)
    temp = 10**18
    nex = -1
    for c in cand:
        if snuke(int(c)) <= temp:
            temp = snuke(int(c))
            nex = int(c)
            
    ans.append(nex)
    cur = nex+1
    
for ai in ans[:k]:
    print(ai)

Submission status: Accepted

Solution code:
K = int(input())
def snuke(n):
  _n = n
  S = n % 10
  while _n:
    _n //= 10
    S += _n % 10
  return n / S
cnt = 0
k = 0
x = 1
sx = 2
while cnt < K:
  a = max(k - 1, 1)
  b = max(k, 1) * 10
  c = int('0' + ('9' * k))
  for i in range(a, b):
    y = x
    sy = sx
    x = i * 10 ** k + c
    sx = snuke(x)
    if sx >= sy:
      print(y)
      cnt += 1
      if cnt >= K:
        break
  k += 1

Submission status: Accepted

Solution code:
def S(i):
    ans = 0
    while i // 10 > 0:
        ans += i % 10
        i //= 10
    ans += i
    return ans

K = int(input())
count, N = 0, 1
while count < K:
    N2, Nd = N, 1
    while N2//10 > 0:
        Nd += 1
        N2 //= 10
    minX, X = N/S(N), N
    for i in range(Nd+2):
        x = (N//10**(i+1) + 1) * 10**(i+1) -1
        if minX > x/S(x):
            minX, X = x/S(x), x
    print(X)
    count += 1
    N = X+1

Submission status: Accepted

Solution code:
def S(i):
    ans = 0
    while i // 10 > 0:
        ans += i % 10
        i //= 10
    ans += i
    return ans

K = int(input())
Ans, count, N = [], 0, 1
while count < K:
    N2, Nd = N, 1
    while N2//10 > 0:
        Nd += 1
        N2 //= 10
    minX, X = N/S(N), N
    for i in range(Nd+2):
        x = (N//10**(i+1) + 1) * 10**(i+1) -1
        if minX > x/S(x):
            minX, X = x/S(x), x
    Ans.append((minX, X))
    count += 1
    N = X+1

for i in range(K):
    print(Ans[i][1])

Submission status: Accepted

Solution code:
def snk_cal(i):
    snk = i
    i = str(i)
    q = 0
    for j in range(len(i)):
        q += int(i[j])
    snk /= q
    return snk

K = int(input())
if K <= 9:
    for i in range(K):
        print(i+1)
else:
    for i in range(9):
        print(i+1)
    K -= 9
    snk = 9
    while K > 0:
        res = snk+1
        d = len(str(res))
        l = []
        for i in range(d):
            n = int(str(res)[:-i-1]+'9'*(i+1))
            l.append(snk_cal(n))
        i = l.index(min(l))
        snk = int(str(res)[:-i-1]+'9'*(i+1))
        print(snk)
        K -= 1

Submission status: Accepted

Solution code:
def R(x):
    return x / sum(map(int, str(x)))
K = int(input())
D = 0
l = 0
for i in range(K):
    D += 10**l
    print(D)
    if 10**l < R(D+10**l):
        l += 1

Submission status: Accepted

Solution code:
def f(x):
    return x / sum(map(int, str(x)))
 
K = int(input()) 
x, y = 1, 1
 
for i in range(K):
    print(x)
    if f(x + y) > f(x + y * 10):
        y *= 10
    x += y

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
res = []
for digit in range(1,16):
    if digit<=3:
        for i in range(2,11):
            res.append(10**(digit-1)*i-1)
    elif 4<=digit<=12:
        for i in range(11,(digit-2)*10):
            res.append(i*10**(digit-2)-1)
        for i in range(digit-2,11):
            res.append(i*10**(digit-1)-1)
    elif digit==15:
        for i in range(101,110):
            res.append(i*10**(digit-3)-1)
        for i in range(11,101):
            res.append(i*10**(digit-2)-1)
    else:
        for i in range(11,101):
            res.append(i*10**(digit-2)-1)
for i in range(int(input())):
    print(res[i])

Submission status: Accepted

Solution code:
K = int(input())

def S(n):
    return sum(int(c) for c in str(n))
d9 = 0
cnt = 0
upper = 1
while cnt < K:
    n = int(str(upper) + ('9' * d9))
    if n <= S(n) * (10 ** d9):
        print(n)
        cnt += 1
        upper += 1
    else:
        d9 += 1
        upper //= 10