Self Numbers

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6960    Accepted Submission(s):
3047

Problem Description
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.

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

 
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
|
|
|
 
Source
 
Recommend
Eddy   |   We have carefully selected several similar
problems for you:  1124 1157 1164 1113 1073 
 
这道题没有输入,看题目的意思写这个数组,直接筛选暴力打表就好。
 
题意:输出这一串数字,1000000以内所有的每个数,加上自身每一位数字,可以生产另一个数,但有些数,不能通过这样产生,请输出这些数。
 
附上代码:
 
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int visit[];
int xx(int n)
{
int sum=;
while(n!=)
{
sum+=n%;
n/=;
}
return sum;
}
int main()
{
int i,j,sum;
memset(visit,,sizeof(visit));
for(i=; i<=; i++) //直接暴力打表
{
sum=i;
sum+=xx(i);
visit[sum]=; //不需要出现的数字标记为0
}
for(i = ; i<=; i++)
{
if(visit[i])
printf("%d\n",i);
}
return ;
}

hdu 1128 Self Numbers的更多相关文章

  1. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  2. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  3. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  4. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  5. HDU 4722 Good Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 Good Numbers Time Limit: 2000/1000 MS (Java/Othe ...

  6. HDU 4320 Arcane Numbers 1 (数论)

    A - Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1058 Humble Numbers(离线打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...

  8. hdu 3117 Fibonacci Numbers

    这道题其实也是水题来的,求Fibonacci数的前4位和后4位,在n==40这里分界开.后4位不难求,因为n达到了10^18的规模,所以只能用矩阵快速幂来求了,但在输出后4位的时候一定要注意前导0的处 ...

  9. HDU 1058 Humble Numbers (DP)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. Springboot 创建的maven获取resource资源下的文件的两种方式

    Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...

  2. Direct2D 第6篇 绘制多种风格的线条

    原文:Direct2D 第6篇 绘制多种风格的线条 上图是使用Direct2D绘制的线条,Direct2D在效率上比GDI/GDI+要快几倍,GDI/GDI+绘图是出了名的"慢", ...

  3. Linux用户程序配置文件

    在 Linux(和一般的 UNIX)中,有无数的“用户”程序.最常见的一种用户程序配置文件是 /etc/lynx.cfg.这是著名的文本浏览器 lynx 的配置文件.通过这个文件,您可以定义代理服务器 ...

  4. Spring_Bean的生命周期

    init-method="init" destroy-method="destory" 指定初始化和销毁方法 创建Bean后置处理器 <!-- 实现Bea ...

  5. struts1之工作原理

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zkn_CS_DN_2013/article/details/34452341 1.初始化:strut ...

  6. oralce系统触发器

    系统事件是指基于oracle事件(例如logon.logoff和startup.shutdown)所建立的触发器,通过使用系统事件触发器,提供了跟踪系统或是数据库变化机制.下面介绍使用的系统事件属性函 ...

  7. 实现自定义docker 镜像共享

    我觉得docker最大的便利性体现在可以实现镜像共享,方便团队在同一环境下开发.当然docker的强大之处不止于此. 接下来我用一个例子来演示如何进行docker镜像共享,步骤如下(Ubuntu): ...

  8. Python sorted

    sorted函数: iterable:是可迭代类型;cmp:用于比较的函数,比较什么由key决定,有默认值,迭代集合中的一项;key:用列表元素的某个属性和函数进行作为关键字,有默认值,迭代集合中的一 ...

  9. JAVA高级--java泛型

    类型的参数化 泛型类可以同时设置多个参数 泛型类可以继承泛型类 泛型类可以实现泛型接口 示例--泛型类 package com.date; public class GenericDemo { pub ...

  10. Date日期类,Canlendar日历类,Math类,Random随机数学类

    Date日期类,SimpleDateFormat日期格式类 Date  表示特定的时间,精确到毫秒 常用方法 getTime() setTime() before() after() compareT ...