「Codeforces Round #441」 Classroom Watch
Discription
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 ≤ 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.
Example
21
1
15
20
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.
很显然每位数的和的贡献不可能太大,对于题目的范围来说肯定是<100的,所以枚举比n小100之内的数就行了。。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int num[1005];
int n,m,k; inline int get(int x){
int an=0,nxt;
while(x){
nxt=x/10;
an+=x-nxt*10;
x=nxt;
}
return an;
} int main(){
cin>>n;
k=max(1,n-100);
for(int i=k;i<n;i++) if(i==n-get(i)) num[++m]=i; printf("%d\n",m);
for(int i=1;i<=m;i++) printf("%d\n",num[i]);
return 0;
}
「Codeforces Round #441」 Classroom Watch的更多相关文章
- 【LOJ #6094. 「Codeforces Round #418」归乡迷途】
题目大意: 传送门. lca说的很明白就不重复了. 题解: 先膜一发lca. 大体读完题以后我们可以知道对于第i个节点最短路一定是连向1到i-1中的某个点. 然后我们考虑将到1距离(这里及以下均是最短 ...
- codeforces Round #441 C Classroom Watch【枚举/注意起点】
C. time limit per test 1 second memory limit per test 512 megabytes input standard input output stan ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- loj #547. 「LibreOJ β Round #7」匹配字符串
#547. 「LibreOJ β Round #7」匹配字符串 题目描述 对于一个 01 串(即由字符 0 和 1 组成的字符串)sss,我们称 sss 合法,当且仅当串 sss 的任意一个长度为 ...
- [LOJ#531]「LibreOJ β Round #5」游戏
[LOJ#531]「LibreOJ β Round #5」游戏 试题描述 LCR 三分钟就解决了问题,她自信地输入了结果-- > -- 正在检查程序 -- > -- 检查通过,正在评估智商 ...
- [LOJ#530]「LibreOJ β Round #5」最小倍数
[LOJ#530]「LibreOJ β Round #5」最小倍数 试题描述 第二天,LCR 终于启动了备份存储器,准备上传数据时,却没有找到熟悉的文件资源,取而代之的是而屏幕上显示的一段话: 您的文 ...
- [LOJ#516]「LibreOJ β Round #2」DP 一般看规律
[LOJ#516]「LibreOJ β Round #2」DP 一般看规律 试题描述 给定一个长度为 \(n\) 的序列 \(a\),一共有 \(m\) 个操作. 每次操作的内容为:给定 \(x,y\ ...
- [LOJ#515]「LibreOJ β Round #2」贪心只能过样例
[LOJ#515]「LibreOJ β Round #2」贪心只能过样例 试题描述 一共有 \(n\) 个数,第 \(i\) 个数 \(x_i\) 可以取 \([a_i , b_i]\) 中任意值. ...
随机推荐
- 三 APPIUM GUI讲解(Windows版)
本文本转自:http://www.cnblogs.com/sundalian/p/5629386.html APPIUM GUI讲解(Windows版) Windows版本的APPIUM GUI有 ...
- 设计模式之模板方法模式 templateMethod
代码实现 public abstract class BankTemplateMethod { //具体方法 public void takeNumber(){ System.out.println( ...
- Windows后续处理工作
1.远程桌面开启,应预先开启windows防火墙,并放行“远程桌面”(TCP 3389)端口,防止用户自行开启防火墙时操作错误. 2.防火墙高级安全-需放行ICMP 3.补丁更新,更新完重启 4.本地 ...
- C# Socket通信的服务器与客户端
客户端代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- (总结)Nginx与Apache、Tomcat、Resin动静分离核心配置
PS:近来有几个刚使用nginx的新童鞋老问我,nginx+fastcgi不够稳定,偶尔出现502错误,怎么解决?本人使用nginx也有3年多了,也认为php-fpm模块不够稳定,在访问量不大的时候没 ...
- ls目录结构
命令ls ls -l = ll -l 详细信息-a 查看隐藏的文件或目录-d 只看目录本身,不列出目录下面的文件和目录 一起使用一般 ls -ld-t 以时间先后排序-i 显示文件节点-h 显示字节大 ...
- Asymptotic I Catalan Number
卡特兰数出现在许多计数问题中. 常见的例子有:$n$ 个节点的有序二叉树,$2n$ 个括号构成的合法括号序列. 在上面所举的两个例子中,很容易看出卡特兰数满足递推: $$ C_{n+1} = \sum ...
- spring in action学习笔记十六:配置数据源的几种方式
第一种方式:JNDI的方式. 用xml配置的方式的代码如下: 1 <jee:jndi-lookup jndi-name="/jdbc/spittrDS" resource-r ...
- hibernate用配置文件的方式实现orm
本文主要讲用配置文件的方式讲如何把一个对象和数据库中的表关联起来,其实用配置文件本质是和用注解的方式是一样的. 思路:1.写一个domain对象(如Person.java) 2.写这个domain对象 ...
- mysql截取字符串与reverse函数
mysql的函数大全: http://www.jb51.net/Special/606.htm 这个网页上很多知识点,可以学习下,关于mysql的函数,也可以作为API查询: 这里只说下mysql的截 ...