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 ...
随机推荐
- GDOI2017第二轮模拟day1 总结
平民比赛 这场比赛的暴力分非常友好. 但是我并没有拿到全部的暴力分. 1(暴力分\(60/100\)) 暂时我可以拿的暴力分为\(30/100\),直接mst模拟即可. 然而当时打了个辣鸡莫队,结果爆 ...
- 完整版unity安卓发布流程(包括SDK有原生系统依赖关系的工程)
要3个东西!NDS,SDK,JDK, NDK官网下载:https://developer.android.google.cn/ndk/downloads/index.html(注意系统是不是64位) ...
- 使用FastJson对实体类和Json还有JSONObject之间的转换
1. 实体类或集合转JSON串 String jsonString = JSONObject.toJSONString(实体类); 2.JSON串转JSONObject JSONObject json ...
- DirectX11笔记(七)--Direct3D渲染3--INDICES AND INDEX BUFFERS
原文:DirectX11笔记(七)--Direct3D渲染3--INDICES AND INDEX BUFFERS 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...
- React map生成元素添加点击事件绑定this
问题 使用.map(function(Item)生成元素添加onClick事件:onClick={this.provinceChange.bind(this, "99")}时,前台 ...
- vue+axios 对restful 请求封装
礼拜天来公司整理项目,项目是最近开始重构的,里面的各种http请求接口是restful结构的(为了提升项目的比格),整理一下笔记 [restful介绍][1]博主讲的很详细 技术栈: vue + vu ...
- prestashop 首页轮播幻灯片图片修改
后台 -> Modules -> Modules 搜索 home(中文则搜幻灯片)
- Liferay Model Hints
这篇文章主要介绍如何通过model hint 来修改liferay builder service生成数据库表中默认字段的长度. 1.什么是Model Hints? 它是对liferay builde ...
- iOS 开发该选择Blocks还是Delegates
http://www.cocoachina.com/ios/20150925/13525.html 前文:网络上找了很多关于delegation和block的使用场景,发现没有很满意的解释,后来无意中 ...
- node服务器的配置
安装node 安装pm2 http://blog.csdn.net/chenlinIT/article/details/73343793 安装mongodbhttp://zixuephp.net/ar ...