(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;}
- (Coderforces 875A)A. Classroom Watch 暴力 + 思维
- Codeforces 875A Classroom Watch
- CodeForces 875A Classroom Watch
- A. Classroom Watch
- Codeforces 875A Classroom Watch 题解
- codeforces——875A —— Classroom Watch
- 【CodeForces】701A - Cards(暴力 || 思维)
- coderforces 348A Mafia(二分)
- New Year Transportation(CoderForces A)
- coderforces 508A 易错
- Coderforces 509A
- Coderforces 396A
- Coderforces 348A
- coderforces 701A Cards
- coderforces-701A-水题
- Coderforces Rond #366 A
- coderforces #364 A Cards
- Codeforces 876 C Classroom Watch 基础数学,暴力
- JAVA Eclipse如何修改Android程序名称
- 【读书笔记——java8函数式编程】第一章 简介 第二章 Lambda表达式
- JAVA Eclipse如何重新设置工作空间workspace
- JAVA Eclipse中的Android程序如何使用线程
- JAVA Eclipse中如何简易的实现消息机制
- (Coderforces 875A)A. Classroom Watch 暴力 + 思维
- JAVA Eclipse Incorrect line ending found carriage return 怎么办
- JAVA Eclipse 启动 Eclipse 弹出“Failed to load the JNI shared library jvm_dll”怎么办
- 【C++】第8章 函数探幽 知识点总结
- 倍福TwinCAT(贝福Beckhoff)基础教程 松下官方软件开启报错伺服未就绪怎么办
- 乔布斯简介
- loj #115. 无源汇有上下界可行流
- 倍福TwinCAT(贝福Beckhoff)基础教程 松下绝对值驱动器如何做初始化设置
- 倍福TwinCAT(贝福Beckhoff)基础教程 松下驱动器如何执行绝对值清零