Self Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20864   Accepted: 11709

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.

Input

No input for this problem.

Output

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

Sample Input

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
这题第一眼看上去就觉得应该要用什么特殊方法,要不然会超时,可是最后没想到根本不会超时,我在调试中提交了n次Runtime error,让我几乎快疯了,后来当我把定义的bool数组移到main函数外就ac了,这让我百思不得其解,难道main函数内部定义一个10000长度的bool数组会超过限制吗
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXn = ;
int numOf_Digit(int number)
{
int sum = number;
while(number>=)
{
sum += number%;
number /=;
}
sum+=number ;
return sum;
}
bool vis[MAXn];
int main()
{ memset(vis,true,sizeof(vis));
for(int i=;i<;i++)
{
int t =numOf_Digit(i);
vis[t] = false;
}
for(int i = ;i<;i++)
if(vis[i]==true)
printf("%d\n",i);
return ;
}

当然直接把#define 去掉,直接就是vis[10000],并且取消掉那个运算函数,用一句int t = i + i/1000+(i/100)%10+(i/10)%10+i%10; 就可以0MS了,但个人风格,喜欢把功能变成函数

最新文章

  1. linux命令:tar
  2. 【代码笔记】iOS-提醒时间的选择
  3. hdu1863 最小生成树(prim)
  4. Linux下rar命令详解
  5. codeforces 361 B - Mike and Shortcuts
  6. 百度分享如何自定义分享url和内容?
  7. MVC基础知识-持续更新....
  8. js: get event handler bound to the element
  9. VS2010 C++ 优化配置
  10. 使用VisualStudio发布ASP.NET网站
  11. 【UML】概念、关联、画画(一)
  12. YII2.0 数据库增删改查
  13. jQuery中的方法
  14. Win7添加php环境变量.
  15. Python学习摘要201802
  16. IIS部署ASP.Net Core 502.5错误和解决
  17. 定时器 setTimeout()超时调用和 setInterval()间歇调用
  18. 2017CCPC秦皇岛 A题Balloon Robot&amp;&amp;ZOJ3981【模拟】
  19. AES 加密问题
  20. Java中集合删除元素时候关于ConcurrentModificationException的迷惑点

热门文章

  1. ES5 object的新函数
  2. Nginx Upload Module 上传模块
  3. poj 1664 放苹果_整数拆分
  4. react-native 自己搭建热更新服务器
  5. 步步学LINQ to SQL:为实体类添加关系【转】
  6. Django学习笔记(三)—— 型号 model
  7. Centos升级gcc4.4.7升级gcc4.8手记
  8. Banner 切换
  9. javascript模式——Mixin
  10. SWFUpload的使用及其注意事项