Self Numbers

Self Numbers
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 22335
Accepted: 12567

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

/***********************************************************************
    Copyright (c) 2015,wangzp
    All rights no reserved.
  
    Name: 《Self Numbers》In PEKING UNIVERSITY ACM
    ID:   PROBLEM 1316
    问题简述:  找出10000以内的自数。什么叫做自数呢?
	           比如:d(75) = 75 + 7 + 5 = 87,87就不是自数;
			   d(1) = 1 + 1 = 2,2也不是自数; 
			   100以内的自数为:1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.
 
    Date: SEP 09, 2015 
 
***********************************************************************/
#include 
   
   
    
    
#include 
    
    
     
     

int a[10001];

void self_num_fun(void)
{
	int i,t1,t2;
	for (i = 1;i <= 10000;i++)
	{
		t1 = t2 = i;
		while(t1)
		{
			t2 += t1 % 10;
			t1 /= 10;
		}
		if (t2 <= 10000)//注意这个条件
		{
			a[t2] = 1;//不是self-number的元素做标记
		}
	}
	//打印self-number
	for (i = 1;i <= 10000;i++)
	{
		if (!a[i])
		{
			printf("%d\n",i);
		}
	}
}

int main(void)
{
	memset(a,0,sizeof(a));//把所有的a元素都初始化为0(代表是self-number)
	self_num_fun();
	return 0;
}

    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1316是一个自数字。根据引用中提供的代码和引用中的解释,自数字是指没有生成器的数字。在引用的例子中,提到了小于100的13个自数,而1316恰好不在其中。因此,我们可以得出结论,1316是一个自数字。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [pku acm 1316 Self Numbers 代码](https://download.csdn.net/download/china8848/394248)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [1316:Self Numbers: 类埃及筛法,换种思路,生活如此简单](https://blog.csdn.net/csyifanZhang/article/details/105256813)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [1316(简单) self number](https://blog.csdn.net/weixin_38293125/article/details/72675261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值