Self Numbers

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

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
尼玛,太简单了,之间就水过去了.....
代码:
 #include<cstdio>
#include<cstring>
#define maxn 1000001
/*求个位数之和*/
int work(int n)
{
int sum=;
while(n>){
sum+=n%;
n/=;
}
return sum;
}
bool ans[maxn];
int main(){
int pos;
//freopen("test.out","w",stdout);
memset(ans,,sizeof(ans));
for(int i=;i<maxn;i++){
pos=i+work(i);
if(pos<=&&!ans[pos]) ans[pos]=;
}
for(int i=;i<maxn;i++){
if(!ans[i])printf("%d\n",i);
}
return ;
}

HDUoj-------(1128)Self Numbers的更多相关文章

  1. 《C#本质论》读书笔记(14)支持标准查询操作符的集合接口

      14.2.集合初始化器 使用集合初始化器,程序员可以采用和数组相似的方式,在集合的实例化期间用一套初始的成员来构造这个集合. 如果没有集合初始化器,就只有在集合实例化后才能显示添加到集合中--例如 ...

  2. Redis(三)Redis附加功能

    一.慢查询分析 许多存储系统(例如MySql)提供慢查询日志帮助开发和运维人员定位系统存在的慢操作. 所谓慢查询日志就是系统在命令执行前后计算每条命令的执行时间,当超过预设阈值,就将这条命令的相关信息 ...

  3. Python的range(n)的用法

    Python的range(n) 方法就是: API定义: If you do need to iterate(迭代) over a sequence(一系列) of numbers, the buil ...

  4. Redis 基础数据结构之二 list(列表)

    Redis 有 5 种基础数据结构,分别为:string (字符串).list (列表).set (集合).hash (哈希) 和 zset (有序集合). 今天来说一下list(列表)这种数据结构, ...

  5. (Problem 21)Amicable numbers

    Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into ...

  6. Round Numbers(组合数学)

    Round Numbers Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

  7. LeetCode(193. Valid Phone Numbers)(sed用法)

    193. Valid Phone Numbers Given a text file file.txt that contains list of phone numbers (one per lin ...

  8. Humble Numbers(hdu1058)

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

  9. HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  10. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

随机推荐

  1. Using Pre-Form Trigger In Oracle Forms

    Pre-Form trigger in Oracle Forms fires during the form start-up, before forms navigates to the first ...

  2. Plotting means and error bars (ggplot2)

    library(ggplot2) ############################################# # summarySE ######################### ...

  3. Django1.9 Python3.4出现Error loading MySQLdb

    linux Errorloading MySQLdb module: No module named MySQLdb 这是因为目前 MySQLdb 还不支持 python3.x ,开源无人维护哈 之前 ...

  4. [HDOJ5543]Pick The Sticks(DP,01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...

  5. C# WPF MVVM 实战 – 5- 用绑定,通过 VM 设置 View 的控件焦点

    本文介绍在 MVVM 中,如何用 ViewModel 控制焦点. 这焦点设置个东西嘛,有些争论.就是到底要不要用 ViewModel 来控制视图的键盘输入焦点.这里不讨论,假设你就是要通过 VM,设置 ...

  6. 请求webservice接口的某方法数据

    NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.com/xxx/xxxxWS?wsdl"]; NSString *soapMs ...

  7. STL--STL和她的小伙伴们:

    STL--概述: 标准模板库(StandardTemplateLibrary,STL),是C++程序设计语言标准模板库.STL是由Alexander Stepanov.Meng Lee和David R ...

  8. C# int.Parse()与int.TryParse()

    int i = -1;bool b = int.TryParse(null, out i);执行完毕后,b等于false,i等于0,而不是等于-1,切记. int i = -1;bool b = in ...

  9. nodePPT 这可能是迄今为止最好的网页版PPT

    demo例子为:http://qdemo.sinaapp.com/#0 下载地址为:https://github.com/ksky521/nodeppt/

  10. MVC服务器前台提示

    [HttpPost] public ActionResult AddMsg(MsgModel model) { string strSql = "insert into tbl_msg(ti ...