codeforces 876 C. Classroom Watch

http://codeforces.com/contest/876/problem/C

 

C. Classroom Watch
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number xwritten in decimal numeral system.

Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

Input

The first line contains integer n (1 ≤ n ≤ 109).

Output

In the first line print one integer k — number of different values of x satisfying the condition.

In next k lines print these values in ascending order.

Examples
input
21
output
1
15
input
20
output
0
Note

In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.

In the second test case there are no such x.

 

题意:

找出所有的x,满足x+x的每一位=n

 

因为n<=1e9,所以最大的数位之和为81

从n-81 开始枚举即可

 

#include<cstdio>
#include<algorithm>

using namespace std;

int n,tot,ans[82];

bool check(int x)
{
    int y=x,cnt=x;
    while(y) cnt+=y%10,y/=10;
    return cnt==n;
}

int main()
{
    scanf("%d",&n);
    for(int i=max(1,n-81);i<=n;i++) 
     if(check(i)) ans[++tot]=i;
    printf("%d\n",tot);
    for(int i=1;i<=tot;i++) printf("%d ",ans[i]);
}

 

 

posted @ 2017-10-22 20:33  TRTTG  阅读(403)  评论(0编辑  收藏  举报