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. Android 性能测试_Monkey 实践【转】

    参考资料:1. Monkey测试策略:https://testerhome.com/topics/597 2. Android Monkey测试详细介绍:http://www.jikexueyuan. ...

  2. 第七十三节,css盒模型

    css盒模型 学习要点: 1.元素尺寸 2.元素内边距 3.元素外边距 4.处理溢出 本章主要探讨HTML5中CSS盒模型,学习怎样了解元素的外观配置以及文档的整体布局. 一.元素尺寸 CSS盒模型中 ...

  3. PAT 团体程序设计天梯赛-练习集 L1-003. 个位数统计

    给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字 ...

  4. JavaScript事件响应的基础语法总结

    1.onclick是鼠标单击事件,当在网页上单击鼠标时,就会发生该事件.同时onclick事件调用的程序块就会被执行,通常与按钮一起使用 //例子 <html> <head> ...

  5. Apple 移动设备绑定动态生成元素点击事件$(document).on('click',element,callback)失效解决方法

    今天在工作中刚接触到了微信社区相关的开发工作,测试的时候发现,动态生成元素的点击事件在andriod设备上可以触发,而在apple移动设备上却无法触发.好奇的我赶紧百度了下,很快就在stackover ...

  6. Dokan[转]

    原文地址:http://www.cnblogs.com/xxonehjh/p/3634889.html 因工作需要,最近与同事合作使用Dokan开发了一个虚拟磁盘的简单程序,初步实现了远程目录映射到本 ...

  7. 网页SEO内容

    关于网页根目录下的robots.txt文件的部分疑问 robots.txt书写语法:第一条:User-agent,后接搜索引擎的蜘蛛名称第二条:Disallow,填写要拦截的部分经典语法:User-a ...

  8. 4、Math对象

    1.编辑html页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...

  9. sql新建数据库表,及添加多个主键

    create table tb_Modules(module_Id int identity(1,1) primary key,  (自增)model_Name varchar(50) not nul ...

  10. html5 读写sqlite数据库

    var db = openDatabase('MyData','','My Database',102400); //首先它创建一个数据库表,里面有3个字段 db.transaction(functi ...