HDUoj-------(1128)Self Numbers

Self Numbers

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6227    Accepted Submission(s): 2728

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

尼玛,太简单了,之间就水过去了.....

代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #define maxn 1000001
 4 /*求个位数之和*/
 5 int work(int n)
 6 {
 7     int sum=0;
 8     while(n>0){
 9       sum+=n%10;
10       n/=10;
11     }
12     return sum;
13 }
14 bool ans[maxn];
15 int main(){
16     int pos;
17     //freopen("test.out","w",stdout);
18     memset(ans,0,sizeof(ans));
19     for(int i=1;i<maxn;i++){
20         pos=i+work(i);
21         if(pos<=1000000&&!ans[pos]) ans[pos]=1;
22     }
23     for(int i=1;i<maxn;i++){
24         if(!ans[i])printf("%d\n",i);
25     }
26 return 0;
27 }

HDUoj-------(1128)Self Numbers

时间: 2024-11-05 21:36:07

HDUoj-------(1128)Self Numbers的相关文章

LeetCode(386)Lexicographical Numbers

题目 Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize your algorithm to use less time and space. The input size may be as large as 5,000,000. 分析 给定一个整数,将1~n内的n个整数

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)

题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Description A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and

Javascript中,数学方法可以分成以下几类: constans(常数)、power functions(乘方函数)、trigonometic functions(三角函数)、rounding functions(舍入函数)、random numbers(随机数字)

在Javascript中,数学方法可以分成以下几类: constans(常数).power functions(乘方函数).trigonometic functions(三角函数).rounding functions(舍入函数).random numbers(随机数字) 常数和乘方函数 Math.E 自然对数的底(为常数) 2.718 Math.LN10 10的自然对数 2.302 Math.LN2 2的自然对数 0.693 Math.PI 圆周率 3.1415 Math.SQRT1_2 1/

leetcode——Add Two Numbers 两个链表表示的正整数对其求和(AC)

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 ->

UVA 11481 - Arrange the Numbers(组合数学)

题目链接:11481 - Arrange the Numbers 题意:序列1-n,进行重排,问最后前m个中有k个仍然位置不变的情况数 思路:之前写过UVA 580, n个数重排,要求每个位置都不同的情况的题目,递推式为dp[i] = (i - 1) * (dp[i - 1] + dp[i - 2]) 利用这个,这题只要: k个位置C(m, k) * sum(C[n - m][i] (后面n-m个选出i个对应正确匹配) * dp[n - k - i](其余位置全都错排)} 这便是总情况数 代码:

[LeetCode] Sum Root to Leaf Numbers(bfs)

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example, 1 / 2 3 T

LeetCode(193. Valid Phone Numbers)(sed用法)

193. Valid Phone Numbers Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. You may assume that a valid phone number must appear in one of the following two f

(数论)D - Beautiful Numbers

D - Beautiful Numbers Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum

gym101102J Divisible Numbers(预处理)

题意: 给你一个n(1e5)q(1e5)表示n个数的数列,q个询问,每次询问给你l(n),r(n),s(1023), s表示一个二进制数列,当前位为1表示对应的这个位上的数出现,比如5表示101,即1和3出现, l,r表示一段区间,这段区间中的每个数,只要能整除出现的数中的任意一个,就会对答案有1的贡献. 问每个询问的贡献. 思路: 由于出现了1就肯定每个数都有贡献(都是1的倍数),然后就可以少一位,用512表示9位出不出现的所有情况, 用n*512的复杂度预处理所有的情况,O(1)查询. fo

(未完成)[HDUOJ]“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛

solved 5 A(签到) 题意:两个人随机得到0或1其中之一数字,每个人都可以猜对方的数字是什么,有一个人猜对就算成功,问最优策略下00,01,10,11四种情况两人的成功概率分别是多少. 题意不明的签到题,题面说两人不能沟通,以为就是两个人随便猜,成功率都是1-0.5*0.5=0.75.结果是两个人可以提前商量好策略,那显然可以其中一个人猜和自己相同的数,另一个人猜和自己不同的数,那么所有的成功率都是100%. #include<bits/stdc++.h> using namespac