108. Self-numbers 2
来源:互联网 发布:前端学到什么水平知乎 编辑:程序博客网 时间:2024/05/22 03:54
108. Self-numbers 2
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands fordigitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence 33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ... The number n is called agenerator ofd(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number withno generators is a self-number. Let the a[i] will be i-th self-number. There are thirteen self-numbers a[1]..a[13] less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97. (the first self-number is a[1]=1, the second is a[2] = 3, :, the thirteen is a[13]=97);
Input
Input contains integer numbers N, K, s1...sk. (1<=N<=107, 1<=K<=5000) delimited by spaces and line breaks.
Output
At first line you must output one number - the quantity of self-numbers in interval [1..N]. Second line must contain K numbers - a[s1]..a[sk], delimited by spaces. It`s a gaurantee, that all self-numbers a[s1]..a[sk] are in interval [1..N]. (for example if N = 100, sk can be 1..13 and cannot be 14, because 14-th self-number a[14] = 108, 108 > 100)
Sample Input
100 101 2 3 4 5 6 7 11 12 13
Sample Output
131 3 5 7 9 20 31 75 86 97
形如 51 + 5 + 1 = 57 则称51是57的初始值,101有两个初始值,分别为: 91 和 100,没有初始值的数称为self数,给出N求N以内的k个self数a[1],a[2]...a[k]
- 108. Self-numbers 2
- 【SGU】108. Self-numbers 2
- Self-numbers 2
- SGU108 Self-numbers 2
- [SGU]108. Self-numbers II
- sgu 108-self-numbers 2
- SGU 108 Self-numbers 2
- sgu 108 Self-numbers 2
- sgu 108 self-numbers 2
- sgu 108 Self-numbers 2
- SGU 108. Self-numbers 2 离线+位优化
- Self Numbers
- Self Numbers
- Self Numbers
- Self Numbers
- SGU 108 Self-numbers 2(数论)
- zoj1180 Self Numbers
- POJ 1316 Self Numbers
- PyQt基本操作
- 贝叶斯集锦:贝叶斯统计基础
- 亿级Web系统搭建——单机到分布式集群
- tms320f28335在制板过程中几个问题总结
- 数据结构之简单选择排序(参考整理严蔚敏数据结构)
- 108. Self-numbers 2
- [软工视频]实践阶段——编码、测试、维护
- 贝叶斯集锦:R和JAGS的交互
- [linux,c++] 基于mutex 的互斥访问队列实现
- 初用新浪SAE服务器做后台 之PHP学习笔记
- SQL中判断字符串中包含字符的方法
- python pyquery
- 骑士飞行棋 - C#控制台小游戏
- MATLAB学习(一)——————format 命令