hdu1128 Self Numbers

简介: hdu1128 Self Numbers

Self Numbers

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


 

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

Mid-Central USA 1998

 

就是要输出1000000以内所有不能由其它数字组成的数字。

AC代码如下:

//1128
#include<stdio.h>
int f[1000001];
int sum(int a)
{
    int ans=a;
    while(a)
    {
        ans+=a%10;
        a/=10;
    }
return ans;
}
int main()
{
    int i;
    for(i=1;i<1000001;i++)
    {
        if(f[i]==0)
            printf("%d\n",i);
        f[sum(i)]=1;
    }
    return 0;
}
目录
相关文章
|
9月前
|
机器学习/深度学习 算法 安全
NeurIPS 2024:数学推理场景下,首个分布外检测研究成果来了
在深度学习领域,模型的鲁棒性与可靠性至关重要。针对数学推理这一复杂生成场景,传统OOD检测方法因输出空间高密度特征而面临挑战。为此,研究团队提出基于轨迹波动性的TV分数方法,通过计算样本嵌入偏移轨迹的波动性来检测OOD样本。实验表明,该方法在数学推理和选择题任务中优于传统算法,展示了其潜在优势和通用性。尽管存在局限性,TV分数为数学推理场景下的OOD检测提供了创新思路。论文地址:https://arxiv.org/abs/2405.14039
213 2
|
小程序 UED 开发者
揭秘支付宝小程序成功之道:UI/UX设计原则与用户体验优化秘籍大公开!
【8月更文挑战第27天】支付宝小程序在移动互联网中扮演着重要角色,优秀的UI/UX设计能显著提升用户满意度。本文首先强调了设计的一致性、简洁性、易用性和响应性原则,确保用户获得顺畅体验。接着,介绍了最佳实践,包括利用支付宝设计组件库保持界面统一、优化加载速度、适应多设备显示、设置清晰导航以及重视用户反馈。最后,提供了一个简单示例展示如何应用支付宝设计组件。遵循这些指导原则,开发者能够构建既美观又实用的小程序。
549 0
|
5天前
|
云安全 人工智能 自然语言处理
|
9天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
865 26
|
4天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
450 4
|
6天前
|
机器学习/深度学习 人工智能 数据可视化
1秒生图!6B参数如何“以小博大”生成超真实图像?
Z-Image是6B参数开源图像生成模型,仅需16GB显存即可生成媲美百亿级模型的超真实图像,支持中英双语文本渲染与智能编辑,登顶Hugging Face趋势榜,首日下载破50万。
384 18
|
12天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
825 59
Meta SAM3开源:让图像分割,听懂你的话