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\)的 ...
随机推荐
- 昂贵的聘礼 Dijkstra法
poj 1062 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39437 Accepted: 11432 Descri ...
- 【转载】.NET面试题系列[0] - 写在前面
原文:.NET面试题系列[0] - 写在前面 索引: .NET框架基础知识[1] - .NET框架基础知识(1) http://www.cnblogs.com/haoyifei/p/5643689.h ...
- jquery之 on()方法
原文地址:http://www.365mini.com/page/jquery-on.htm on()函数用于为指定元素的一个或多个事件绑定事件处理函数. 此外,你还可以额外传递给事件处理函数一些所需 ...
- change the walltime for currently running PBS job (qalter pbs)
qalter jobid -l walltime=X e.g.qalter 377470.manager -l walltime=2222:00:00qalter: Unauthorized Requ ...
- CNV
CNV: 人类主要是二倍体.如果有些区域出现3个.4个拷贝,那就是扩增了,如果只出现1个拷贝,就是缺失.所以CNV分析是依靠特定位置的测序深度来估算的,先在染色体上划窗,然后看每个窗口的平均测序深度, ...
- Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!
http://codeforces.com/contest/435/problem/C
- Codeforces Round #377 (Div. 2) C. Sanatorium 水题
C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- .NET 4.0 任务和并行编程系列
8天玩转并行开发 8天玩转并行开发——第一天 Parallel的使用 8天玩转并行开发——第二天 Task的使用 8天玩转并行开发——第三天 plinq的使用 8天玩转并行开发——第四天 同步机制(上 ...
- LINQ之路 2:C# 3.0的语言功能(上)
在上一篇的LINQ介绍中,我们已经看到了隐式类型变量var,扩展方法(extension method)和lambda表达式的身影.没错,他们正是LINQ技术的基石,是他们让LINQ的实现成为可能,并 ...
- Android简单登陆页面
布局: 线性布局+相对布局 日志打印: 利用LogCat和System.out.println打印观察. Onclick事件是采用过的第四种: 在配置文件中给Button添加点击时间 涉及知识: 通过 ...