hdu 1128 Self Numbers
Self Numbers
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6960 Accepted Submission(s):
3047
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.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int visit[];
int xx(int n)
{
int sum=;
while(n!=)
{
sum+=n%;
n/=;
}
return sum;
}
int main()
{
int i,j,sum;
memset(visit,,sizeof(visit));
for(i=; i<=; i++) //直接暴力打表
{
sum=i;
sum+=xx(i);
visit[sum]=; //不需要出现的数字标记为0
}
for(i = ; i<=; i++)
{
if(visit[i])
printf("%d\n",i);
}
return ;
}
hdu 1128 Self Numbers的更多相关文章
- 【数位DP】 HDU 4722 Good Numbers
原题直通车: HDU 4722 Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
- HDOJ(HDU).1058 Humble Numbers (DP)
HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...
- hdu 3117 Fibonacci Numbers 矩阵快速幂+公式
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...
- HDU 4722 Good Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 Good Numbers Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 4320 Arcane Numbers 1 (数论)
A - Arcane Numbers 1 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1058 Humble Numbers(离线打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...
- hdu 3117 Fibonacci Numbers
这道题其实也是水题来的,求Fibonacci数的前4位和后4位,在n==40这里分界开.后4位不难求,因为n达到了10^18的规模,所以只能用矩阵快速幂来求了,但在输出后4位的时候一定要注意前导0的处 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- python输出最大公约数和最小公倍数
def myfun(): num1 = int(input('输入num1')) num2 = int(input('输入num2')) list1=[] for i in range(1, max( ...
- python 结构化的数据
- IDEA 运行maven项目配置
- 软件测试 → 第二章 基础-> 软件缺陷与缺陷管理
一.缺陷定义与分类 1.1.软件缺陷 定义:在软件工程整个生命周期中任何背离需求.无法正确完成用户所要求的功能的问题,包括存在于组件.设备.或系统软件中因异常条件不支持而导致系统失败等都属于缺陷. 从 ...
- Directx教程(30) 如何保证渲染物体不会变形
原文:Directx教程(30) 如何保证渲染物体不会变形 在Directx11教程(6)中, 我们曾经实现过这个功能,但那时是在SystemClass中,处理WM_SIZE时候,重新调用m ...
- codechef Heavy-light Decompositions
Heavy-light Decompositions Problem Code: HLDOTSSubmit All submissions for this problem are available ...
- PHP Laravel系列之环境搭建( VirtualBox+Vagrant+Homestead+系列网址)
搭建环境从来都是阻挡一门新技能的最致命的硬伤,为了这个环境,我又是花费了半天的时间,各种问题层出不穷,下面基于网上的一些教程(我看到的都多少有些问题) 开始的时候是在实验楼这个平台上开始学习的,不过 ...
- 整合Freemarker视图层和整合jsp视图层和全局捕获异常
SpringBoot静态资源访问 1.静态资源:访问 js / css /图片,传统web工程,webapps springboot 要求:静态资源存放在resource目录下(可以自定义文件存放) ...
- c++ 对象池的创建
template <class T> class ObjectPool { public: using DeleterType = std::function<void(T*)> ...
- dataframe添加元素指定为列表,不同for循环命名空间下的变量重复问题
split=pd.DataFrame({'data':[0],'len':0,'count':0},index=[0])for i_t in range(over_128.shape[0]): ct= ...