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 C++14 (Clang 3.8.0) (judge verdict: Accepted)

#include <iostream>
#include <vector>

using namespace std;

typedef pair<long, long> P;

long sum(long n){
    long tmp = 1;
    long ans = 0;
    while(tmp <= n){
        ans += (n%(tmp*10)-ans)/tmp;
        tmp *= 10;
    }
    return ans;
}

int main(){
    int K;
    
    vector<P> v;
    cin >> K;
    long pow[16];
    pow[0] = 1;
    for(int i = 1; i <= 15; i++) pow[i] = pow[i-1]*10;

    for(int i = 1; i <= 15; i++){
        if(i == 1){
            for(int j = 1; j <= 9; j++){
                v.push_back(P(j, sum(j)));
            }
        }
        if(i == 2){
            for(int j = 10; j <= 99; j++){
                v.push_back(P(j, sum(j)));
            }
        }
        if(i == 3){
            for(int j = 100; j <= 999; j++){
                v.push_back(P(j, sum(j)));
            }
        }
        if(i >= 4){
            for(int j = 1000; j <= 9999; j++){
                v.push_back(P(j*pow[i-4]+pow[i-4]-1, sum(j*pow[i-4]+pow[i-4]-1)));
            }
        }
    }
    double tmp_min = 10e+16;
    vector<long> ans;
    for(int i = v.size()-1; i >= 0; i--){
        if(tmp_min >= (double)v[i].first/(double)v[i].second) {
            ans.push_back(v[i].first);
            tmp_min = (double)v[i].first/(double)v[i].second;
        }
    }
    
    for(int i = 1; i <= K; i++){
        cout << ans[ans.size()-i];
        if(i != K) cout << ' ';
        else cout << endl;
    }
}