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 for digitadition, 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 a generator of d(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 with no generators is a self-number. There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.

Input

No input for this problem.

Output

Write a program to output all positive self-numbers less than 10000 in increasing order, one per line.

Sample Input


Sample Output

1
3
5
7
9
20
31
42
53
64
|
| <-- a lot more numbers
|
9903
9914
9925
9927
9938
9949
9960
9971
9982
9993
题解:
   基础题。题目不难,只要能够理解题意的话就能够顺利的做出来了.
    
代码:
 /*
Name: Self Number
Copyright:
Author:
Date: 11/08/17 04:23
Description:
*/
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int NUM = ;
int record[NUM];
int judge(int i)
{
int temp = i;
while(i)
{
temp += i%;
i /= ;
}
return temp; /*返回非self number*/
} int main()
{
memset(record,,sizeof(record)); /*数组初始化,是一个好习惯*/
for(int i = ; i < NUM;i++)
{
int temp = judge(i);
if(temp < NUM )
record[temp] = ; /*将不是self number的整数标记为1*/
}
bool flag = false;
for(int i = ; i < NUM;i++)
{ if(record[i] == )/*注意输出格式 最后一个不空行*/
{
if(flag)
cout<<endl;
cout<<i;
flag = true;
} }
return ;
}

ACM Self Number的更多相关文章

  1. 第一届山东省ACM——Phone Number(java)

    Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...

  2. [ACM_搜索] POJ 1096 Space Station Shielding (搜索 + 洪泛算法Flood_Fill)

    Description Roger Wilco is in charge of the design of a low orbiting space station for the planet Ma ...

  3. Balanced and stabilized quicksort method

    The improved Quicksort method of the present invention utilizes two pointers initialized at opposite ...

  4. Mine Number(搜索,暴力) ACM省赛第三届 G

    Mine Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Every one once played the gam ...

  5. ACM—Number Sequence(HDOJ1005)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 主要内容: A number sequence is defined as follows: f ...

  6. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  7. ACM解题之在线翻译 Give Me the Number

    Give Me the Number Time Limit: 2 Seconds                                     Memory Limit: 65536 KB  ...

  8. ACM HDU 1755 -- A Number Puzzle

    A Number Puzzle Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

随机推荐

  1. UIView圆角设置

    对于UIview的圆角设置最简单的就是layer的两个属性分别是cornerRadius和masksToBounds,但是对于设置其中某一个角为圆角的时候需要使用贝塞尔曲线 UIView *aView ...

  2. JavaScript 克隆

    JavaScript 克隆 本次学习内容: 克隆:只克隆标签和属性,不克隆文本. 克隆的功能,如果不添加使用Ture,就只会克隆标签和属性,不会克隆文本. 克隆的参数全部是节点对象,不能是字符串 &l ...

  3. 爬取IP

    import urllib.request import re def url_open(url): req = urllib.request.Request(url,headers={'User-A ...

  4. 微信小程序:wx.request之post请求后端无法获取数据的问题

    前言:小程序的开发中总是踩到各种坑,看文档也不知所云: 例如当我们在写微信小程序接口时,method请求方式有POST和GET两种,为了数据安全,我们会偏向于使用POST请求方式访问服务器端: 问题: ...

  5. Java中的变量数据类型补充

    Java中变量的数据类型的补充 变量按照数据类型进行分类 1.基本数据类型 数值型:①整数类型(byte,short,int,long)②浮点型(float,doubbe)③字符型(char)④布尔型 ...

  6. win10安装Ubuntu14.04双系统

    1 制作镜像 UltralISO刻录镜像到U盘,下载地址:http://pan.baidu.com/s/1o7JpthS 2压缩空间给Ubuntu安装 使用windows自带的压缩(磁盘管理) 3安装 ...

  7. 洛谷 P3258 [JLOI2014]松鼠的新家(树链剖分)

    题目描述松鼠的新家是一棵树,前几天刚刚装修了新家,新家有n个房间,并且有n-1根树枝连接,每个房间都可以相互到达,且俩个房间之间的路线都是唯一的.天哪,他居然真的住在”树“上. 松鼠想邀请小熊维尼前来 ...

  8. Treap讲解

    Treap讲解 上一篇blog提出了Treap这个算法,在这里我就要详细讲解. 首先,我们可以从字面上理解这个算法,Treap这个单词是由Tree和Heap两个单词构成的,所以它的性质就很好理解了,明 ...

  9. openSUSE设置局域网的时间同步

  10. 出错信息:Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'username'

    出错信息: java.sql.SQLException: Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'username ...