Self Numbers

Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 34   Accepted Submission(s) : 16
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

 #include <stdio.h>
#include <string.h>
int sum[]={};
int All_sum(int n)
{
if (n<)
return n;
else
return (n%)+All_sum(n/);
} void num(int i,int n)
{
int j,k=i-*n,tmp;
if(k<)
k=;
while()
{
tmp=k;
if(k>i)
return ;
tmp+=All_sum(k);
if(tmp==i)
{sum[tmp]+=;return ;}
k++;
}
return ;
} int main()
{
int i,n,Len,k,a,j;
for(i=;i<=;i++)
{
if(i<)n=;else if(i<)n=; else if(i<)n=; else if(i<)n=; else if(i<)n=; else if(i<)n=;
if(sum[i]==)
{
num(i,n);
}
if(sum[i]==)
printf("%d\n",i);
}
return ;
}

Self Numbers的更多相关文章

  1. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  2. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  3. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  4. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  5. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  6. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] Consecutive Numbers 连续的数字

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. [LeetCode] Compare Version Numbers 版本比较

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

  10. [LeetCode] Sum Root to Leaf Numbers 求根到叶节点数字之和

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

随机推荐

  1. JavaScript eval() 为什么使用eval()是一个坏主意 什么时候可以使用eval()

    ---------------------------------------------------------------------------------------------------- ...

  2. ModelDriven

    功能:  submit 之后显示结果  1.项目结构 2.web.xml <?xml version="1.0" encoding="UTF-8"?> ...

  3. slf4j 之logback日志之环境安装【一】

    一.maven引用. 传送门:http://www.slf4j.org/manual.html#projectDep <dependency> <groupId>ch.qos. ...

  4. Faster-R-CNN编译使用及相应问题解决

    1.首先opencv是需要安装的,我用的ubuntu14.04,opencv3.0,具体安装教程可以参考网上很多,不想多提. 2.安装几个依赖包:cython,python-opencv和easydi ...

  5. c#委托与事件(详解)

    引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...

  6. 转:apache 的mod-status

    最近发现在apache的监控方面,apache 2开始自带的apache mod-status其实是个不错的工具,下面摘录并笔记之: 如果是linux的话,可以这样设置: 在httpd.conf中添加 ...

  7. USACO 2.3 Cow Pedigrees

    Cow Pedigrees Silviu Ganceanu -- 2003 Farmer John is considering purchasing a new herd of cows. In t ...

  8. socket编程——一个简单的例子

    从一个简单的使用TCP例子开始socket编程,其基本步骤如下: server                                                  client ++++ ...

  9. ckplayer 项目实战

    <div class="control-group" id="videoDiv" style="display: none;"> ...

  10. hdu和poj的基础dp30道

    题目转自:https://crazyac.wordpress.com/dp%E4%B8%93%E8%BE%91/ 1.hdu 1864 最大报销额 唔,用网上的算法连自己的数据都没过,hdu的数据居然 ...