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++ (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
long funcS(long N);
int main(){
    long K;
    cin>>K;
    long i=1,num=1,nines=0;
    float sunuke=0;
    long pp=0;
    while(i<=K){
        long p;
        if(num>=10){
            num=1;
            nines++;
        }
        p=num;

        // prlongf("%d",num);
        for(long k=0;k<nines;k++){
            // prlongf("9");
            p*=10;
            p+=9;
        }
        // prlongf("\n");
        if(pp!=0){
            p-=pow(10,nines-1)*pp;
        }
        long funs=funcS(p);
        if(sunuke <= (float)p/funs){
            cout<<p<<endl;
            sunuke= (float)p/funs;
            pp=0;
        }else{
            pp++;
        }
        num++;
        i++;
    }
}
long funcS(long N){
    long keta=0;
    for(long i=N;i!=0;keta++){
        i/=10;
    }
    // cout<<keta<<endl;
    long num=0;
    long temN=N;
    long temN2=N;
    for(long i=keta-1;i>=0;i--){
        temN/=10;
        num+=temN2-temN*10;
        temN2/=10;
    }
    return num;
}
// (long num,long deep){
//     while(tem!=num){
//         ones++;

//         tem=
//     }
//     return target;
// }