Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏

时间:2022-12-20 00:24:43
Self Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 22101   Accepted: 12429

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
就是筛选出10000以内的Self Numbers,类似素数筛
#include <cstdio>
#include <string.h>
#include <cmath>
#include <iostream>
#include <algorithm>
#define WW freopen("output.txt","w",stdout)
using namespace std;
const int Max=10000;
bool vis[Max];
int main()
{
memset(vis,false,sizeof(vis));
for(int i=1; i<Max; i++)
{
if(!vis[i])
{
int ans=i;
while(ans<Max)
{
int ant=ans;
while(ans)
{
ant+=(ans%10);
ans/=10;
}
ans=ant;
if(!vis[ans])
vis[ans]=true;
else
{
break;
}
}
}
}
for(int i=1; i<Max; i++)
{
if(vis[i])
continue;
printf("%d\n",i);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏的更多相关文章

  1. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20&colon;53 2人阅读 评论&lpar;0&rpar; 收藏

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...

  2. Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20&colon;48 81人阅读 评论&lpar;0&rpar; 收藏

    #include<iostream> #include<stack> #include<stdio.h> using namespace std; struct n ...

  3. hadoop调优之一:概述 分类: A1&lowbar;HADOOP B3&lowbar;LINUX 2015-03-13 20&colon;51 395人阅读 评论&lpar;0&rpar; 收藏

    hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...

  4. NYOJ 119 士兵杀敌(三)【ST算法】 分类: Brush Mode 2014-11-13 20&colon;56 101人阅读 评论&lpar;0&rpar; 收藏

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=119 解题思路: RMQ算法. 不会的可以去看看我总结的RMQ算法. http://blo ...

  5. bzoj 1041 圆上的整点 分类: Brush Mode 2014-11-11 20&colon;15 80人阅读 评论&lpar;0&rpar; 收藏

    这里先只考虑x,y都大于0的情况 如果x^2+y^2=r^2,则(r-x)(r+x)=y*y 令d=gcd(r-x,r+x),r-x=d*u^2,r+x=d*v^2,显然有gcd(u,v)=1且u&l ...

  6. HTTP 错误 500&period;19- Internal Server Error 错误解决方法 分类: Windows服务器配置 2015-01-08 20&colon;16 131人阅读 评论&lpar;0&rpar; 收藏

    1.第一种情况如下: 解决方法如下: 经过检查发现是由于先安装Framework组件,后安装iis的缘故,只需重新注册下Framework就可以了,具体步骤如下 1 打开运行,输入cmd进入到命令提示 ...

  7. winform Execl数据 导入到数据库(SQL) 分类: WinForm C&num; 2014-05-09 20&colon;52 191人阅读 评论&lpar;0&rpar; 收藏

    首先,看一下我的窗体设计: 要插入的Excel表: 编码 名称 联系人 电话 省市 备注 100 100线 张三 12345678910 北京 测试 101 101线 张三 12345678910 上 ...

  8. Latex插入图片 分类: LaTex 2014-11-18 20&colon;07 261人阅读 评论&lpar;0&rpar; 收藏

    在Latex中插入图片的方式很多,我这里只介绍自己常用的一种方式,欢迎大家指导. 我习惯于使用graphicx宏包来插入图片,有时候会配合上subfigure宏包来同时插入多幅图片组合. 首先,需要在 ...

  9. House Robber 分类: leetcode 算法 2015-07-09 20&colon;53 2人阅读 评论&lpar;0&rpar; 收藏

    DP 对于第i个状态(房子),有两种选择:偷(rob).不偷(not rob) 递推公式为: f(i)=max⎧⎩⎨⎪⎪{f(i−1)+vali,f(i−2)+vali,robi−1==0robi−1 ...

随机推荐

  1. java中的包以及内部类的介绍

    1:形式参数和返回值的问题(理解)    (1)形式参数:        类名:需要该类的对象        抽象类名:需要该类的子类对象        接口名:需要该接口的实现类对象    (2)返 ...

  2. linux 系统管理 使用技巧

    一.这篇文章讲了什么? 这篇文章很有参考性哈.本来是想等一段时间有更多条技巧后在发布的,不过,突然发现,我是去年的今天在博客园落户了,祝我的博客一周岁快乐,希望以后多分享一些文章啦.所以就把草稿箱的其 ...

  3. Cheatsheet&colon; 2013 09&period;01 ~ 09&period;09

    .NET Multi Threaded WebScraping in CSharpDotNetTech .NET Asynchronous Patterns An Overview of Projec ...

  4. python中的类中属性元素加self&period;和不加self&period;的区别

    在类中,self只能在函数中使用,表示的是实例属性,就是每个实例可以设置不值,而不相互影响.如果在类级别使用没有self的属性,是类属性,一般作为全局变量来用的.事实上:就是一个是类属性 一个是对象属 ...

  5. Struts2基本包作用详解

    asm-3.3.jar作用:操作java字节码的类库包路径及主要类:未提供 asm-commons-3.3.jar作用:提供了基于事件的表现形式包路径及主要类:未提供 asm-tree-3.3.jar ...

  6. Python爬虫使用Selenium&plus;PhantomJS抓取Ajax和动态HTML内容

    1,引言 在Python网络爬虫内容提取器一文我们详细讲解了核心部件:可插拔的内容提取器类gsExtractor.本文记录了确定gsExtractor的技术路线过程中所做的编程实验.这是第二部分,第一 ...

  7. pytorch实现DCGAN、pix2pix、DiscoGAN、CycleGAN、BEGAN以及VAE

    https://github.com/sunshineatnoon/Paper-Implementations

  8. 【ASP&period;NET MVC 学习笔记】- 19 REST和RESTful Web API

    本文参考:http://www.cnblogs.com/willick/p/3441432.html 1.目前使用Web服务的三种主流的方式是:远程过程调用(RPC),面向服务架构(SOA)以及表征性 ...

  9. Oracle ROWID具体解释

    1.ROWID定义 ROWID:数据库中行的全局唯一地址 对于数据中的每一行,rowid伪列返回行的地址.rowid值主要包括下面信息: 对象的数据对象编号 该行所在的数据文件里的数据块 该行中数据块 ...

  10. RedHat 安装RabbitMQ

    (以下均以root用户执行) 1.安装配置epel源rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noar ...