B. Perfect Number
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
We consider a positive integer perfect, if and only if the sum of its digits is exactly 1010. Given a positive integer kk, your task is to find the kk-th smallest perfect positive integer.
Input
A single line with a positive integer kk (1≤k≤100001≤k≤10000).
Output
A single number, denoting the kk-th smallest perfect integer.
Examples
input
Copy
1
output
Copy
19
input
Copy
2
output
Copy
28
Note
The first perfect integer is 1919 and the second one is 2828.
暴力可过。
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n=0;
int a;
scanf("%d",&a);
for(int i=18; i<=a*10000; i++)
{
int sum=0;
int c=i;
while(c!=0)
{
sum+=c%10;
c=c/10;
}
if(sum==10)
{
n++;
}
if(n==a)
{
printf("%lld\n",i);
break;
}
}
return 0;
}