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.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long k = in.nextLong();
		if(k<=9) {
			for(int i=1;i<=k;i++) {
				System.out.println(i);
			}
		}else if(k<=18) {
			printDigit1();
			for(int i=10;i<=k;i++) {
				System.out.println(10*(i-9)+9);
			}
		}else {
			printDigit1();
			printDigit2();
			long target = 109;
			long prevTargetDigit = 3;
			long add=10;
			for(long i=19;i<=k;i++) {
				while(true) {
					if(prevTargetDigit!=getDigit(target)) {
						target = (long) Math.pow(10, getDigit(target)-1) + (long) Math.pow(10, getDigit(target)-getDigit(getDigitSum(target))) -1;
						prevTargetDigit = getDigit(target);
					}
					boolean found = false;
					long test = target + add;
					long limit = (1+getFirstNumber(target))*(long) Math.pow(10, getDigit(target)-1);
					while(!found && test<limit) {
						if((double)target/getDigitSum(target) > (double)test/getDigitSum(test)) {
							found = true;
							break;
						}
						test += add;
					}
					if(found) {
						target += add;
					}else {
						System.out.println(target);
						add = (long) Math.pow(10, getDigit(target)-getDigit(getDigitSum(target)));
						target += add;
						break;
					}
				}
			}
		}
	}
	
	public static void printDigit1() {
		for(int i=1;i<10;i++) {
			System.out.println(i);
		}
	}
	
	public static void printDigit2() {
		for(int i=1;i<10;i++) {
			System.out.println(10*i+9);
		}
	}
	
	public static long getDigitSum(long num) {
		long sum = 0;
		while(num>0) {
			sum += num % 10;
			num /= 10;
		}
		return sum;
	}
	
	public static long getDigit(long num) {
		long digit = 0;
		while(num>0) {
			digit++;
			num /= 10;
		}
		return digit;
	}
	
	public static long getFirstNumber(long num) {
		while(num>=10) {
			num /= 10;
		}
		return num;
	}

}