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:
#!/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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    a = s.count("-")
    b = s.count("+")
    print(b-a)
    return

#B
def B():
    n = S()
    num = sum(map(int, n))
    n = int("".join(n))
    print(["Yes", "No"][n % num > 0])
    return

#C
def C():
    n, k = LI()
    LI()
    print((n - k) // (k - 1) + 1 + bool((n - k) % (k - 1)))
    return

# D
# 解説AC
# 解説むずくね？これでわかる人いる？
# 順に理解していく
# 1) 桁数が上がるとx/S(x)が上昇するのは解説を見ればわかる
#
# 2) 下一桁が9であることを理解する
# xの下一桁が9でないとして
# x/S(x) - (x+1)/S(x+1) について S(x) =y として
# x/y - (x+1)/(y+1) = x/y - x/(y+1) - 1/(y+1)
#                   = x * (1/y - 1/(y+1)) - 1/(y+1)
#                   = x/y/(y+1) - 1/(y+1)
#                   = (x/y - 1)/(y+1) → (1)
# 今明らかにx/y >= 1なので (1) > 0 だから
# x/y > (x+1)/(y+1)
# よって下一桁は大きいほうがいいので9である
#
# 3)繰上りがない場合変化させる桁は
# できるだけ小さいほうがいいということを示す
# 元の数をxとしてi桁目とi+1桁目について変化させるとすると
# どう考えてもx/S(x)はS(x)は同等の上昇がみられる
# 対しi+1桁目のほうがxが上昇するためi桁目の
# ほうがよいことがわかる
# しかし、繰上りがある場合はどちらがいいかは直感的には言えない 
# 
# 4) 確定させた桁の数が9であり、変わらないことを示す
# つまり変化させられる桁(そこの桁をi桁目として10**(i-1)をxに足す
# と最小値がとりうると考えられる)がi桁目としてi-1桁目より小さな桁
# について変化させる意味がないことを示す 
# x/S(x) - (x+10^(i-1))/S(x+1) について上と同様にすれば
# = (x/y - 10**(i-1)) / y が言えるので 
# x/y が 10**(i-1) を上回っている場合
# その桁より小さい値を変化させるとx/S(x)が減少することがわかる
# x/S(x)がx以上の整数でx/S(x)を一番小さくできるのであるから、
# 一度上回った 10**(i-1) をx/S(x)が下回ることはあり得ない
# つまり極限まで大きくしておく必要のある最大桁以下はすべて9にしておく
# 
# 4)このまま毎回x/yの値を計算してそれの桁数から足す10**(i-1)
# を計算してもよいが、変化させる桁目をi桁目としてi+1桁目を変化させた
# ほうがx/S(x)が小さくなるという状態は
# つまりx/yが10**(i-1)を上回ったという
# 意味になるためもっと計算量を落とした方法が本解法になる 
def D():
    K = II()
    ans = 1
    i = 0
    def Sunuke(a):
        return a / sum(map(int, str(a)))
    def Check(a, i):
        return Sunuke(a + 10 ** i) > Sunuke(ans + 10 ** (i + 1))
    while K:
        print(ans)
        K -= 1
        i += Check(ans, i)
        ans += 10 ** i
    return


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

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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    a = s.count("-")
    b = s.count("+")
    print(b-a)
    return

#B
def B():
    n = S()
    num = sum(map(int, n))
    n = int("".join(n))
    print(["Yes", "No"][n % num > 0])
    return

#C
def C():
    n, k = LI()
    LI()
    print((n - k) // (k - 1) + 1 + bool((n - k) % (k - 1)))
    return

# D
# 解説AC
# 解説むずくね？これでわかる人いる？
# 順に理解していく
# 1) 桁数が上がるとx/S(x)が上昇するのは解説を見ればわかる
#
# 2) 下一桁が9であることを理解する
# xの下一桁が9でないとして
# x/S(x) - (x+1)/S(x+1) について S(x) =y として
# x/y - (x+1)/(y+1) = x/y - x/(y+1) - 1/(y+1)
#                   = x * (1/y - 1/(y+1)) - 1/(y+1)
#                   = x/y/(y+1) - 1/(y+1)
#                   = (x/y - 1)/(y+1) → (1)
# 今明らかにx/y >= 1なので (1) > 0 だから
# x/y > (x+1)/(y+1)
# よって下一桁は大きいほうがいいので9である
#
# 3)繰上りがない場合変化させる桁は
# できるだけ小さいほうがいいということを示す
# 元の数をxとしてi桁目とi+1桁目について変化させるとすると
# どう考えてもx/S(x)はS(x)は同等の上昇がみられる
# 対しi+1桁目のほうがxが上昇するためi桁目の
# ほうがよいことがわかる 
# 
# 4) 確定させた桁の数が変わらないことを示す
# つまり変化させられる桁(そこの桁をi桁目として10**(i-1)をxに足す
# と最小値がとりうると考えられる)がi桁目としてi-1桁目より小さな桁
# について変化させる意味がないことを示す 
# x/S(x) - (x+10^(i-1))/S(x+1) について上と同様にすれば
# = (x/y - 10**(i-1)) / y が言えるので 
# x/y が 10**(i-1) を上回っている場合
# その桁より小さい値を変化させてもx/S(x)が減少しないことがわかる
# x/S(x)がx以上の整数でx/S(x)を一番小さくできるのであるから、
# 一度上回った 10**(i-1) をx/S(x)が下回ることはあり得ない
# よって、変化させられる桁がi桁目としてi-1桁目より小さな桁
# について変化させる意味がないことがわかった
# 
# 4)このまま毎回x/yの値を計算してそれの桁数から足す10**(i-1)
# を計算してもよいが、変化させる桁目をi桁目としてi+1桁目を変化させた
# ほうがx/S(x)が小さくなるという状態は
# つまりx/yが10**(i-1)を上回ったという
# 意味になるためもっと計算量を落とした方法が本解法になる 
def D():
    K = II()
    ans = 1
    i = 0
    def Sunuke(a):
        return a / sum(map(int, str(a)))
    def Check(a, i):
        return Sunuke(a + 10 ** i) > Sunuke(ans + 10 ** (i + 1))
    while K:
        print(ans)
        K -= 1
        i += Check(ans, i)
        ans += 10 ** i
    return


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

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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    a = s.count("-")
    b = s.count("+")
    print(b-a)
    return

#B
def B():
    n = S()
    num = sum(map(int, n))
    n = int("".join(n))
    print(["Yes", "No"][n % num > 0])
    return

#C
def C():
    n, k = LI()
    LI()
    print((n - k) // (k - 1) + 1 + bool((n - k) % (k - 1)))
    return

#D
def D():
    K = II()
    ans = 1
    i = 0
    def Sunuke(a):
        return a / sum(map(int, str(a)))
    def Check(a, i):
        return Sunuke(a + 10 ** i) > Sunuke(ans + 10 ** (i + 1))
    while K:
        print(ans)
        K -= 1
        i += Check(ans, i)
        ans += 10 ** i

    return


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

Submission status: Accepted

Solution code:
def main():
    s=set()
    for digit in range(16):
        for i in range(1,1000):
            c=i*10**digit+int('9'*digit or 0)
            if c<10**15:
                s.add(c)
    c=sorted(s)
    for i,n in enumerate(c):
        sn=n/sum(map(int,str(n)))
        for m in c[i+1:i+11]:
            sm=m/sum(map(int,str(m)))
            if sm<sn:
                s.remove(n)
                break
    print(*sorted(s)[:int(input())],sep='\n')
main()

Submission status: Accepted

Solution code:
def main():
    s=set()
    for digit in range(16):
        for i in range(1,1000):
            c=i*10**digit+int('9'*digit or 0)
            if c<10**15:
                s.add(c)
    c=sorted(s)
    for i,n in enumerate(c):
        sn=n/sum(map(int,str(n)))
        for m in c[i+1:i+20]:
            sm=m/sum(map(int,str(m)))
            if sm<sn:
                s.remove(n)
                break
    print(*sorted(s)[:int(input())],sep='\n')
main()

Submission status: Accepted

Solution code:
def main():
    s=set()
    for digit in range(16):
        for i in range(1,1000):
            c=i*10**digit+int('9'*digit or 0)
            if c<10**15:
                s.add(c)
    c=sorted(s)
    for i,n in enumerate(c):
        sn=n/sum(map(int,str(n)))
        for m in c[i+1:i+50]:
            sm=m/sum(map(int,str(m)))
            if sm<sn:
                s.remove(n)
                break
    print(*sorted(s)[:int(input())],sep='\n')
main()

Submission status: Accepted

Solution code:
k = int(input())

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

digit = 0
ans = 1
for _ in range(k):
    print(ans)
    if snuke(ans + 10 ** digit) > snuke(ans + 10 ** (digit + 1)):
        digit += 1
    ans += 10 ** digit

Submission status: Accepted

Solution code:
def f(N):
    l = 0
    NN = N
    while True:
        l += 1
        NN //= 10
        if NN < 10:
            break
    m = N / sum(map(int,list(str(N))))
    num = -1
    for d in range(0,l+2):
        x = (10 ** (d+1)) * int(N/(10**(d+1))+1) - 1
        sx = sum(map(int,list(str(x))))
        value = x/sx
        if value < m:
            m = value
            num = d
    if num == -1:
        return N
    else:
        return (10 ** (num+1)) * int(N/(10**(num+1))+1) - 1

K = int(input())

N = 1
ans = [1]

while len(ans) < K:
    N = f(N+1)
    ans.append(N)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def main():
    def f(N):
        S = 0
        tmp = N
        while tmp > 0:
            S += tmp%10
            tmp //= 10
        return N/S
    
    import sys
    input = sys.stdin.readline
    K = int(input())
    Ans = []
    for i in range(1,10):
        Ans.append(i)
    
    tmp = 0
    T = 1
    nine = 1
    while tmp < 10**15:
        N = T*10**nine + 10**nine - 1
        if f(N) <= f(N+10**nine):
            Ans.append(N)
            T += 1
        else:
            nine += 1
            T //= 10
        tmp = T*10**nine + 10**nine - 1
    print(*Ans[:K],sep = "\n")
    
    
main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

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

def main():
    k = ri()
    cand = list(range(1, 10))
    last = 9
    for n in range(1, 15):
        pow10n = pow(10, n)
        for d in range(1, 10):
            lim = (d+1)*pow10n
            e = 0
            while True:
                e1 = d*pow10n+e*(last+1)+last
                if e1 >= lim:
                    break
                e2 = e1 + (last+1)
                if calc(e1) > calc(e2):
                    last = last*10+9
                    e = 0
                    continue
                cand.append(e1)
                e += 1
    cand = sorted(list(set(cand)))
    print("\n".join(map(str, cand[:k])))


if __name__ == '__main__':
    main()

"""
1 1.0
2 1.0
3 1.0
4 1.0
5 1.0
6 1.0
7 1.0
8 1.0
9 1.0
19 1.9
29 2.6363636363636362
39 3.25
49 3.769230769230769
59 4.214285714285714
69 4.6
79 4.9375
89 5.235294117647059
99 5.5
199 10.473684210526315
299 14.95
399 19.0
499 22.681818181818183
599 26.043478260869566
699 29.125
799 31.96
899 34.57692307692308
999 37.0
1099 57.8421052631579
1199 59.95
1299 61.857142857142854
1399 63.59090909090909
1499 65.17391304347827
1599 66.625
1699 67.96
1799 69.1923076923077
1899 70.33333333333333
1999 71.39285714285714
2999 103.41379310344827
3999 133.3
4999 161.25806451612902
5999 187.46875
6999 212.0909090909091
7999 235.26470588235293
8999 257.1142857142857
9999 277.75
10999 392.82142857142856
11999 413.7586206896552
12999 433.3
13999 451.5806451612903
14999 468.71875
15999 484.8181818181818
16999 499.97058823529414
17999 514.2571428571429
18999 527.75
19999 540.5135135135135
20999 724.1034482758621
21999 733.3
22999 741.9032258064516
23999 749.96875
24999 757.5454545454545
25999 764.6764705882352
26999 771.4
27999 777.75
28999 783.7567567567568
29999 789.4473684210526
39999 1025.6153846153845
49999 1249.975
59999 1463.3902439024391
69999 1666.642857142857
79999 1860.4418604651162
89999 2045.4318181818182
99999 2222.2
109999 2972.945945945946
119999 3157.8684210526317
129999 3333.3076923076924
139999 3499.975
149999 3658.512195121951
159999 3809.5
169999 3953.4651162790697
179999 4090.8863636363635
189999 4222.2
199999 4347.804347826087
209999 5526.289473684211
219999 5641.0
229999 5749.975
239999 5853.634146341464
249999 5952.357142857143
259999 6046.488372093023
269999 6136.340909090909
279999 6222.2
289999 6304.326086956522
299999 6382.95744680851
309999 7948.692307692308
319999 7999.975
329999 8048.756097560976
339999 8095.214285714285
349999 8139.511627906977
359999 8181.795454545455
369999 8222.2
379999 8260.847826086956
389999 8297.851063829787
399999 8333.3125
499999 10204.061224489797
599999 11999.98
699999 13725.470588235294
799999 15384.596153846154
899999 16981.11320754717
999999 18518.5
"""

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

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

def f(n):
    ld = list(map(int, str(n)))
    cand = []
    for i in range(len(ld)-1):
        d = len(ld)-1-i
        ld[d] = 9
        for i in range(1, 10):
            if i < ld[d-1]:
                continue
            ld[d-1] = i
            p = int("".join(map(str, ld)))
            cand.append((calc(p), p))
    cand.sort()
    return cand[0][1]

MAX = 10**15
def main():
    k = ri()
    cand = list(range(1, 10))
    n = 10
    while True:
        if n > MAX:
            break
        p = f(n)
        cand.append(p)
        n = p+1
    print("\n".join(map(str, cand[:k])))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s=set()
    for digit in range(16):
        for i in range(1,1000):
            c=i*10**digit+int('9'*digit or 0)
            if c<10**15:
                s.add(c)
    c=sorted(s)
    for i,n in enumerate(c):
        sn=n/sum(map(int,str(n)))
        for m in c[i+1:i+100]:
            sm=m/sum(map(int,str(m)))
            if sm<sn:
                s.remove(n)
                break
    print(*sorted(s)[:int(input())],sep='\n')
main()

Submission status: Accepted

Solution code:
print(*[1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 199, 299, 399, 499, 599, 699, 799, 899, 999, 1099, 1199, 1299, 1399, 1499, 1599, 1699, 1799, 1899, 1999, 2999, 3999, 4999, 5999, 6999, 7999, 8999, 9999, 10999, 11999, 12999, 13999, 14999, 15999, 16999, 17999, 18999, 19999, 20999, 21999, 22999, 23999, 24999, 25999, 26999, 27999, 28999, 29999, 39999, 49999, 59999, 69999, 79999, 89999, 99999, 109999, 119999, 129999, 139999, 149999, 159999, 169999, 179999, 189999, 199999, 209999, 219999, 229999, 239999, 249999, 259999, 269999, 279999, 289999, 299999, 309999, 319999, 329999, 339999, 349999, 359999, 369999, 379999, 389999, 399999, 499999, 599999, 699999, 799999, 899999, 999999, 1099999, 1199999, 1299999, 1399999, 1499999, 1599999, 1699999, 1799999, 1899999, 1999999, 2099999, 2199999, 2299999, 2399999, 2499999, 2599999, 2699999, 2799999, 2899999, 2999999, 3099999, 3199999, 3299999, 3399999, 3499999, 3599999, 3699999, 3799999, 3899999, 3999999, 4099999, 4199999, 4299999, 4399999, 4499999, 4599999, 4699999, 4799999, 4899999, 4999999, 5999999, 6999999, 7999999, 8999999, 9999999, 10999999, 11999999, 12999999, 13999999, 14999999, 15999999, 16999999, 17999999, 18999999, 19999999, 20999999, 21999999, 22999999, 23999999, 24999999, 25999999, 26999999, 27999999, 28999999, 29999999, 30999999, 31999999, 32999999, 33999999, 34999999, 35999999, 36999999, 37999999, 38999999, 39999999, 40999999, 41999999, 42999999, 43999999, 44999999, 45999999, 46999999, 47999999, 48999999, 49999999, 50999999, 51999999, 52999999, 53999999, 54999999, 55999999, 56999999, 57999999, 58999999, 59999999, 69999999, 79999999, 89999999, 99999999, 109999999, 119999999, 129999999, 139999999, 149999999, 159999999, 169999999, 179999999, 189999999, 199999999, 209999999, 219999999, 229999999, 239999999, 249999999, 259999999, 269999999, 279999999, 289999999, 299999999, 309999999, 319999999, 329999999, 339999999, 349999999, 359999999, 369999999, 379999999, 389999999, 399999999, 409999999, 419999999, 429999999, 439999999, 449999999, 459999999, 469999999, 479999999, 489999999, 499999999, 509999999, 519999999, 529999999, 539999999, 549999999, 559999999, 569999999, 579999999, 589999999, 599999999, 609999999, 619999999, 629999999, 639999999, 649999999, 659999999, 669999999, 679999999, 689999999, 699999999, 799999999, 899999999, 999999999, 1099999999, 1199999999, 1299999999, 1399999999, 1499999999, 1599999999, 1699999999, 1799999999, 1899999999, 1999999999, 2099999999, 2199999999, 2299999999, 2399999999, 2499999999, 2599999999, 2699999999, 2799999999, 2899999999, 2999999999, 3099999999, 3199999999, 3299999999, 3399999999, 3499999999, 3599999999, 3699999999, 3799999999, 3899999999, 3999999999, 4099999999, 4199999999, 4299999999, 4399999999, 4499999999, 4599999999, 4699999999, 4799999999, 4899999999, 4999999999, 5099999999, 5199999999, 5299999999, 5399999999, 5499999999, 5599999999, 5699999999, 5799999999, 5899999999, 5999999999, 6099999999, 6199999999, 6299999999, 6399999999, 6499999999, 6599999999, 6699999999, 6799999999, 6899999999, 6999999999, 7099999999, 7199999999, 7299999999, 7399999999, 7499999999, 7599999999, 7699999999, 7799999999, 7899999999, 7999999999, 8999999999, 9999999999, 10999999999, 11999999999, 12999999999, 13999999999, 14999999999, 15999999999, 16999999999, 17999999999, 18999999999, 19999999999, 20999999999, 21999999999, 22999999999, 23999999999, 24999999999, 25999999999, 26999999999, 27999999999, 28999999999, 29999999999, 30999999999, 31999999999, 32999999999, 33999999999, 34999999999, 35999999999, 36999999999, 37999999999, 38999999999, 39999999999, 40999999999, 41999999999, 42999999999, 43999999999, 44999999999, 45999999999, 46999999999, 47999999999, 48999999999, 49999999999, 50999999999, 51999999999, 52999999999, 53999999999, 54999999999, 55999999999, 56999999999, 57999999999, 58999999999, 59999999999, 60999999999, 61999999999, 62999999999, 63999999999, 64999999999, 65999999999, 66999999999, 67999999999, 68999999999, 69999999999, 70999999999, 71999999999, 72999999999, 73999999999, 74999999999, 75999999999, 76999999999, 77999999999, 78999999999, 79999999999, 80999999999, 81999999999, 82999999999, 83999999999, 84999999999, 85999999999, 86999999999, 87999999999, 88999999999, 89999999999, 99999999999, 109999999999, 119999999999, 129999999999, 139999999999, 149999999999, 159999999999, 169999999999, 179999999999, 189999999999, 199999999999, 209999999999, 219999999999, 229999999999, 239999999999, 249999999999, 259999999999, 269999999999, 279999999999, 289999999999, 299999999999, 309999999999, 319999999999, 329999999999, 339999999999, 349999999999, 359999999999, 369999999999, 379999999999, 389999999999, 399999999999, 409999999999, 419999999999, 429999999999, 439999999999, 449999999999, 459999999999, 469999999999, 479999999999, 489999999999, 499999999999, 509999999999, 519999999999, 529999999999, 539999999999, 549999999999, 559999999999, 569999999999, 579999999999, 589999999999, 599999999999, 609999999999, 619999999999, 629999999999, 639999999999, 649999999999, 659999999999, 669999999999, 679999999999, 689999999999, 699999999999, 709999999999, 719999999999, 729999999999, 739999999999, 749999999999, 759999999999, 769999999999, 779999999999, 789999999999, 799999999999, 809999999999, 819999999999, 829999999999, 839999999999, 849999999999, 859999999999, 869999999999, 879999999999, 889999999999, 899999999999, 909999999999, 919999999999, 929999999999, 939999999999, 949999999999, 959999999999, 969999999999, 979999999999, 989999999999, 999999999999, 1099999999999, 1199999999999, 1299999999999, 1399999999999, 1499999999999, 1599999999999, 1699999999999, 1799999999999, 1899999999999, 1999999999999, 2099999999999, 2199999999999, 2299999999999, 2399999999999, 2499999999999, 2599999999999, 2699999999999, 2799999999999, 2899999999999, 2999999999999, 3099999999999, 3199999999999, 3299999999999, 3399999999999, 3499999999999, 3599999999999, 3699999999999, 3799999999999, 3899999999999, 3999999999999, 4099999999999, 4199999999999, 4299999999999, 4399999999999, 4499999999999, 4599999999999, 4699999999999, 4799999999999, 4899999999999, 4999999999999, 5099999999999, 5199999999999, 5299999999999, 5399999999999, 5499999999999, 5599999999999, 5699999999999, 5799999999999, 5899999999999, 5999999999999, 6099999999999, 6199999999999, 6299999999999, 6399999999999, 6499999999999, 6599999999999, 6699999999999, 6799999999999, 6899999999999, 6999999999999, 7099999999999, 7199999999999, 7299999999999, 7399999999999, 7499999999999, 7599999999999, 7699999999999, 7799999999999, 7899999999999, 7999999999999, 8099999999999, 8199999999999, 8299999999999, 8399999999999, 8499999999999, 8599999999999, 8699999999999, 8799999999999, 8899999999999, 8999999999999, 9099999999999, 9199999999999, 9299999999999, 9399999999999, 9499999999999, 9599999999999, 9699999999999, 9799999999999, 9899999999999, 9999999999999, 10999999999999, 11999999999999, 12999999999999, 13999999999999, 14999999999999, 15999999999999, 16999999999999, 17999999999999, 18999999999999, 19999999999999, 20999999999999, 21999999999999, 22999999999999, 23999999999999, 24999999999999, 25999999999999, 26999999999999, 27999999999999, 28999999999999, 29999999999999, 30999999999999, 31999999999999, 32999999999999, 33999999999999, 34999999999999, 35999999999999, 36999999999999, 37999999999999, 38999999999999, 39999999999999, 40999999999999, 41999999999999, 42999999999999, 43999999999999, 44999999999999, 45999999999999, 46999999999999, 47999999999999, 48999999999999, 49999999999999, 50999999999999, 51999999999999, 52999999999999, 53999999999999, 54999999999999, 55999999999999, 56999999999999, 57999999999999, 58999999999999, 59999999999999, 60999999999999, 61999999999999, 62999999999999, 63999999999999, 64999999999999, 65999999999999, 66999999999999, 67999999999999, 68999999999999, 69999999999999, 70999999999999, 71999999999999, 72999999999999, 73999999999999, 74999999999999, 75999999999999, 76999999999999, 77999999999999, 78999999999999, 79999999999999, 80999999999999, 81999999999999, 82999999999999, 83999999999999, 84999999999999, 85999999999999, 86999999999999, 87999999999999, 88999999999999, 89999999999999, 90999999999999, 91999999999999, 92999999999999, 93999999999999, 94999999999999, 95999999999999, 96999999999999, 97999999999999, 98999999999999, 99999999999999, 100999999999999, 101999999999999, 102999999999999, 103999999999999, 104999999999999, 105999999999999, 106999999999999, 107999999999999, 108999999999999, 109999999999999, 119999999999999, 129999999999999, 139999999999999, 149999999999999, 159999999999999, 169999999999999, 179999999999999, 189999999999999, 199999999999999, 209999999999999, 219999999999999, 229999999999999, 239999999999999, 249999999999999, 259999999999999, 269999999999999, 279999999999999, 289999999999999, 299999999999999, 309999999999999, 319999999999999, 329999999999999, 339999999999999, 349999999999999, 359999999999999, 369999999999999, 379999999999999, 389999999999999, 399999999999999, 409999999999999, 419999999999999, 429999999999999, 439999999999999, 449999999999999, 459999999999999, 469999999999999, 479999999999999, 489999999999999, 499999999999999, 509999999999999, 519999999999999, 529999999999999, 539999999999999, 549999999999999, 559999999999999, 569999999999999, 579999999999999, 589999999999999, 599999999999999, 609999999999999, 619999999999999, 629999999999999, 639999999999999, 649999999999999, 659999999999999, 669999999999999, 679999999999999, 689999999999999, 699999999999999, 709999999999999, 719999999999999, 729999999999999, 739999999999999, 749999999999999, 759999999999999, 769999999999999, 779999999999999, 789999999999999, 799999999999999, 809999999999999, 819999999999999, 829999999999999, 839999999999999, 849999999999999, 859999999999999, 869999999999999, 879999999999999, 889999999999999, 899999999999999, 909999999999999, 919999999999999, 929999999999999, 939999999999999, 949999999999999, 959999999999999, 969999999999999, 979999999999999, 989999999999999, 999999999999999][:int(input())])

Submission status: Accepted

Solution code:
import numpy as np

def set_power(a, power_array):
    res = 1
    for i in range(len(power_array)):
        power_array[i] = res
        res *= a


def solve(ans, K, arr):
    p = 0
    for d in range(15):
        pow = arr[d]
        x = pow - 1
        for i in range(1, 10):
            if d > 2:
                y = i * pow + arr[d - 1] - 1
                if y <= (9*(d - 1) + 1)*arr[d - 1]:
                    for j in range(0, 9):
                        if d > 9:
                            z = i*pow + j*arr[d - 1] + arr[d - 2] - 1
                            if z <= (9 * (d - 2) + j + 1) * arr[d - 2]:
                                for j2 in range(0, 9):
                                    ans[p] = z + j2 * arr[d - 2]
                                    p += 1
                        ans[p] = y + j * arr[d - 1]
                        p += 1
            ans[p] = i * pow + x
            p += 1
    return p

K = int(input())
ans = np.empty(10000, dtype=np.int64)
power_array = np.empty(16, dtype=np.int64)
set_power(10, power_array)
p = solve(ans, K, power_array)
print(*ans[:K].tolist(), sep='\n')

Submission status: Accepted

Solution code:
def snuke(n) :
    s=sum(map(int,str(n)))
    return n/s

k=int(input())
digit=0
ans=1
for _ in range(k):
    print(ans)
    if snuke(ans+10**digit)>snuke(ans+10**(digit+1)):
        digit+=1
    ans+=10**digit

Submission status: Accepted

Solution code:
K = int(input())

def calc_sunuke(num):
    st = str(num)
    s_num = 0
    for c in st:
        s_num += int(c)
    return num / s_num

def search_sunuke(num):
    num_sunuke = calc_sunuke(num)
    if num >= 100:
        digits = len(str(num))
        if digits < 12:
            for i in range(count + 10**(digits-2), 10**digits, 10**(digits-2)):
                if num_sunuke > calc_sunuke(i):
                    return False
            return True
        else:
            for i in range(count + 10**(digits-3), 10**digits, 10**(digits-3)):
                if num_sunuke > calc_sunuke(i):
                    return False
            return True
    else:
        for i in range(count+1, 100):
            if num_sunuke > calc_sunuke(i):
                return False
        return True



count = 1
sunuke_num = 0
while sunuke_num != K:
    if search_sunuke(count):
        print(count)
        sunuke_num += 1
    if count < 99:
        count += 1
    else:
        count_str = str(count)
        digits = len(count_str)
        r_count = count
        if digits < 12:
            for c in count_str:
                if c != '9':
                    count += 10**(digits - 2)
                    break
            if r_count == count:
                count += 10**(digits - 1)
        else:
            for c in count_str:
                if c != '9':
                    count += 10**(digits - 3)
                    break
            if r_count == count:
                count += 10**(digits - 2)

Submission status: Accepted

Solution code:
K = int(input())

def nd(n):
    ans = 0
    nn = n
    while(nn > 0):
        ans += nn%10
        nn //= 10
    return ans/n

def k_next(k):
  d = 1
  c_max = 0
  ans = k
  while(d < k*10):
    cand = (k//d+1)*d+(k%d)
    if nd(cand) >= c_max:
      c_max = nd(cand)
      ans = cand
    d *= 10
  return ans

k = 1
for i in range(K):
  print(k)
  k = k_next(k)

Submission status: Accepted

Solution code:
K = int(input())

def sunuke(n) :
    sumN = sum(map(int, list(str(n))))
    return n / sumN

digit = 0
now = 1

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

Submission status: Accepted

Solution code:
k=int(input())
ans=[]
for i in range(1,10): #1桁の数
  ans.append(str(i))
  
for i in range(1,10): #2桁の数
  ans.append(str(i)+'9')
  
for i in range(1,10): #3桁の数
  ans.append(str(i)+'99')
  
for i in range(10): #4桁の数
  ans.append('1'+str(i)+'99')
for i in range(2,10): #4桁の数
  ans.append(str(i)+'999')
  
for i in range(1,3): #5桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'999')
for i in range(3,10): #5桁の数
  ans.append(str(i)+'9999')
  
for i in range(1,4): #6桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'9999')
for i in range(4,10): #6桁の数
  ans.append(str(i)+'99999')
  
for i in range(1,5): #7桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'99999')
for i in range(5,10): #7桁の数
  ans.append(str(i)+'999999')

for i in range(1,6): #8桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'999999')
for i in range(6,10): #8桁の数
  ans.append(str(i)+'9999999')
  
for i in range(1,7): #9桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'9999999')
for i in range(7,10): #9桁の数
  ans.append(str(i)+'99999999')

for i in range(1,8): #10桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'99999999')
for i in range(8,10): #10桁の数
  ans.append(str(i)+'999999999')

for i in range(1,9): #11桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'999999999')
for i in range(9,10): #11桁の数
  ans.append(str(i)+'9999999999')
  
for i in range(1,10): #12桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'9999999999')
for i in range(10,10): #12桁の数
  ans.append(str(i)+'99999999999')

for i in range(1,10): #13桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'99999999999')
for i in range(10,10): #13桁の数
  ans.append(str(i)+'999999999999')
  
for i in range(1,10): #14桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'999999999999')
for i in range(10,10): #14桁の数
  ans.append(str(i)+'9999999999999')

for i in range(10): #15桁の数
  ans.append('10'+str(i)+'999999999999')
for i in range(1,10): #15桁の数
  ans.append('1'+str(i)+'9999999999999')
for i in range(2,10): #15桁の数
  for j in range(10):
    ans.append(str(i)+str(j)+'9999999999999')
  
for val in ans[:k]:
  print(val)