E

Problem description

We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.

Input

A single line with a positive integer k (1 ≤ k ≤ 10 000).

Output

A single number, denoting the k-th smallest perfect integer.

Examples

Input

1

Output

19

Input

2

Output

28

Note

The first perfect integer is 19 and the second one is 28.

解题思路:题目的意思就是找出升序序列(每个数的每位数字总和都为10)中第k个数。暴力水过!

AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,k=0,tmp,sum,obj[10005];bool flag;
 6     for(int i=1;k<10000;++i){
 7         tmp=i;sum=0;flag=false;
 8         while(!flag && tmp){
 9             if(sum>=10)flag=true;//如果sum超过10就无需再比较下去了,因为此时的i一定不满足要求
10             sum+=tmp%10;
11             tmp/=10;
12         }
13         if(!flag && sum==10)obj[k++]=i;
14     }
15     cin>>n;
16     cout<<obj[n-1]<<endl;
17     return 0;
18 }
原文地址:https://www.cnblogs.com/acgoto/p/9104977.html