codeforce --- Perfect Number
阿新 • • 發佈:2019-01-28
B. Perfect Number
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
int k;
scanf("%d",&k);
int cnt = 0;
ll x;
for(ll a = 19;; a ++)
{
x = a;
int sum = 0;
while(x)
{
sum=sum+x%10;
x/=10;
}
if(sum==10)
cnt++;
if(cnt==k)
{
printf ("%lld",a);
return 0;
}
}
return 0;
}