首页 > 其他 > 详细

E - Perfect Number

时间:2018-05-29 14:51:55      阅读:234      评论:0      收藏:0      [点我收藏+]

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就无需再比较下去了
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 }

 

E - Perfect Number

原文:https://www.cnblogs.com/acgoto/p/9104977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!