hdu 1128 Self Numbers

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

Mid-Central
USA 1998

Recommend

Eddy   |   We have carefully selected several similar
problems for you:  1124 1157 1164 1113 1073

这道题没有输入,看题目的意思写这个数组,直接筛选暴力打表就好。

题意:输出这一串数字,1000000以内所有的每个数,加上自身每一位数字,可以生产另一个数,但有些数,不能通过这样产生,请输出这些数。

附上代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int visit[1000001];
 6 int xx(int n)
 7 {
 8     int sum=0;
 9     while(n!=0)
10     {
11         sum+=n%10;
12         n/=10;
13     }
14     return sum;
15 }
16 int main()
17 {
18     int i,j,sum;
19     memset(visit,1,sizeof(visit));
20     for(i=1; i<=1000000; i++)   //直接暴力打表
21     {
22         sum=i;
23         sum+=xx(i);
24         visit[sum]=0;         //不需要出现的数字标记为0
25     }
26     for(i = 1; i<=1000000; i++)
27     {
28         if(visit[i])
29             printf("%d\n",i);
30     }
31     return 0;
32 }
时间: 2024-10-09 21:03:24

hdu 1128 Self Numbers的相关文章

hdu 3117 Fibonacci Numbers

点击此处即可传送到hdu 3117 **Fibonacci Numbers** Problem Description The Fibonacci sequence is the sequence of numbers such that every element is equal to the sum of the two previous elements, except for the first two elements f0 and f1 which are respectively

hdu 4722 Good Numbers(dp)

public static void main(String[] args) { String a=null; if("aa".equals(a))//这种情形,不出现空指针异常 //if(a.equals("aa"))//出现空指针异常 { System.out.println(true); } else { System.out.println(false); } } 上面的两句不同的比较语句测试,第一句不出现空指针异常,第二句出现. 所以在变量和常量比较的时候

HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵快速幂)

HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵快速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的前四位和后四位. 不足8位直接输出. 分析: 前四位有另外一题HDU 1568,用取对的方法来做的. 后四位可以用矩阵快速幂,MOD设成10000就行了. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * Blog: http://blog.csdn.

HDU 1058 Humble Numbers (dp+打表)

先是想筛法素数表啊,然后1~2000000000枚举打表啊,结果越想越不对. 后来想到唯一分解定理,可是怎么实现呢..果然还是需要努力啊.. 研究了discuss代码,码之~ ~~~~ dp的思想,若dp[i]是Humble Numbers,那么dp[i]*2,dp[i]*3,dp[i]*5,dp[i]*7都将是Humble Numbers. 所以只需要注意连续性便好了. #include<cstdio> #include<algorithm> #include<cmath&

HDU 4325 Vampire Numbers 打表

杭电服务器是慢啊.. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set> #include <vector> #include <map> using namespace std; #define ll long long #define N

HDU 1058 Humble Numbers (打表)

题目链接:HDU 1058 Humble Numbers 题意:一些数他们的素数因子只有2,3,5,7.求这些数. 因为这些数的因子只可能是2,3,5,7.所以通过2,3,5,7这个四个数构造这个数列,这个数列靠后的数必定是前面的数乘上2,3,5,7得到. AC代码: #include<stdio.h> #include<set> #define ll __int64 using namespace std; set<ll> s; set<ll>::iter

hdu 4722 Good Numbers(初涉数位dp)

http://acm.hdu.edu.cn/showproblem.php?pid=4722 大致题意:若一个整数的各位数字之和是10的倍数,称这个数为"good number".给出区间[A,B],求出该区间内"good number"的数的个数. 第一道数位dp,折腾了半天才明白怎么回事. 设dp[site][mod]表示到第site位(由高位向低位)前面各位数字之和对10取余为mod的数的个数,进行记忆化搜索.有两个很重要的点,首先是变量up,表示是否到达边界

HDU 4722 Good Numbers (数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 思路:数位dp,dp[i][j]表示到第i位,数字和%10为j,然后进行dp,注意完全匹配的情况是要+1,而其他情况是从0 到 9 都要考虑 代码: #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; int

HDU 1058 Humble Numbers(DP,数)

题意  所有只能被2,3,5,7这4个素数整除的数称为Humble Number  输入n  输出第n个Humble Number 1是第一个humble number  对于一个Humble Number  a  有2*a,3*a,5*a,7*a都是Humble Number  可以以1为基数  依次展开即可得到一定范围内的Humble Number 用i,j,k,l分别记录 2,3,5,7分别乘到了第几个Humble Number  当前在计算第cnt个Humble Number  那么有