HDUoj-------(1128)Self Numbers
Self Numbers
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6227 Accepted Submission(s): 2728
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.
9949
9960
9971
9982
9993
|
|
|
#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的更多相关文章
- 《C#本质论》读书笔记(14)支持标准查询操作符的集合接口
14.2.集合初始化器 使用集合初始化器,程序员可以采用和数组相似的方式,在集合的实例化期间用一套初始的成员来构造这个集合. 如果没有集合初始化器,就只有在集合实例化后才能显示添加到集合中--例如 ...
- Redis(三)Redis附加功能
一.慢查询分析 许多存储系统(例如MySql)提供慢查询日志帮助开发和运维人员定位系统存在的慢操作. 所谓慢查询日志就是系统在命令执行前后计算每条命令的执行时间,当超过预设阈值,就将这条命令的相关信息 ...
- Python的range(n)的用法
Python的range(n) 方法就是: API定义: If you do need to iterate(迭代) over a sequence(一系列) of numbers, the buil ...
- Redis 基础数据结构之二 list(列表)
Redis 有 5 种基础数据结构,分别为:string (字符串).list (列表).set (集合).hash (哈希) 和 zset (有序集合). 今天来说一下list(列表)这种数据结构, ...
- (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 ...
- Round Numbers(组合数学)
Round Numbers Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
- 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 ...
- Humble Numbers(hdu1058)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)
Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
随机推荐
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类
转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...
- IO设计模式:Reactor和Proactor对比
IO设计模式:Reactor和Proactor对比 平时接触的开源产品如Redis.ACE,事件模型都使用的Reactor模式:而同样做事件处理的Proactor,由于操作系统的原因,相关的开源产品也 ...
- C#中Application.DoEvents()的作用
Visual Studio里的摘要:处理当前在消息队列中的所有 Windows 消息. 交出CPU控制权,让系统可以处理队列中的所有Windows消息,比如在大运算量循环内,加Application. ...
- DOM 表单应用
1.大小写转换 <script> var a='aaa'; var b='AaA'; var c='BbB'; //alert(c.toLowerCase()); //把含有大写的字母转换 ...
- 大学生学习编程(PHP)
在v2ex上看到一大三的求职实习,然后有人给出了建议,个人觉得也挺好,做个记录./ 原帖地址 @ARjson问: 大三的学生党,求实习岗位,现居北京.后端PHP一年半开发经验,熟悉speedphp, ...
- ubuntu安装jdk-6u45-linux-x64.bin___ZC_20160423
for : Android4.4源码编译 环境 : ubuntu12.04_desktop_amd64 1. 1.1.jdk-6u45-linux-x64.bin 放置于 /home 1.2.命令&q ...
- (linux) 常用命令 干货
内容提要 1. 第一难度, 重要 梯队 (grep, awk, sed, find, ) 2. 第二常用, 重要 梯队 (ps, ls, date, fuser, netstat, kill) 3. ...
- css 的小细节,小总结
CSS的一些零碎总结 1.CSS 伪元素用于向某些选择器设置特殊效果(用来当作一个东西的,跟一个元素差不多,但不是元素). ① :frist-line伪元素:用于向文本首行设置特殊样式,但是只能用于块 ...
- html frames
http://blog.sina.com.cn/s/blog_67697189010116o0.html *********************************************** ...