B. Perfect Number
time limit per test2 seconds
memory limit per test256 megabytes
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.
解题心得:
- 题意是问你第n个所有位数之和加在一起为10的数是多少,刚开始也不知道数据范围,写了一个暴力程序跑了一下极限数据,极限数据也就1e7 多一点,时间给了2s,暴力轻松过。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+100;
long long num[maxn],tot = 0;
long long get_sum(int x)
{
int sum = 0;
while(x)
{
int temp = x%10;
sum += temp;
x /= 10;
}
return sum;
}
int main()
{
int n;
scanf("%d",&n);
for(long long i=19;;i++)
{
long long sum = get_sum(i);
if(sum == 10)
{
tot++;
if(tot == n)
{
printf("%lld",i);
break;
}
}
}
return 0;
}