(Coderforces 875A)A. Classroom Watch 暴力 + 思维

来源:互联网 发布:歌曲识别软件 编辑:程序博客网 时间:2024/06/05 08:42

A. 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 x written 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 ≤ 1e9).

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
115

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.

题意:
给你一个数n,让你求所有的x,满足x + (x的每一位数字) == n
先输出满足的x的个数k
按照升序输出所有的x

分析:
直接暴力就可以了。不过n<=1e9不能每次从1开始
由于所以的位数之和一定小于100,所以最多可以从暴力枚举n-100~n就可以了

AC代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <map>using namespace std;const int maxn = 100000;int ans[maxn];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int k = 0;        int i = max(1,n-100);        for(;i<=n;i++)        {            int sum = i;            int t = i;            while(t)            {                sum += t % 10;                t /= 10;            }            if(sum == n)            {                ans[k++] = i;            }        }        printf("%d\n",k);        for(int i=0;i<k;i++) printf("%d\n",ans[i]);    }    return 0;}
原创粉丝点击