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 in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long K = scanner.nextLong();

    long n = 1;
    double s = 1.d;
    for (long i = 1; i <= K; i++) {
      long x = n;
      long z = 0;
      long y = 1;
      while (x > 0) {
        x /= 10;
        z = z * 10 + 9;
        y *= 10;
        long t = x * y + z;
        double ts = sunuke(t);
        if (ts < s) {
          n = t;
          s = ts;
        }
      }
      System.out.println(n);
      n++;
      s = sunuke(n);
    }
  }

  private static double sunuke(long n) {
    return (double) n / sumDigits(n);
  }

  private static long sumDigits(long i) {
    long sum = 0;
    while (i > 0) {
      sum += i % 10;
      i /= 10;
    }
    return sum;
  }

  private static long numDigits(long i) {
    long d = 0;
    while (i > 0) {
      d++;
      i /= 10;
    }
    return d;
  }
}