POJ 1316 Self Numbers(我的水题之路——筛法)
2012-01-28 21:32
387 查看
Self Numbers
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
Source
Mid-Central USA 1998
存在一种数字,它可以用另一个数和那个数本身各个位数之和表示,比如51可以用39+3+9表示,则要求输出10000以内,所有不能用这种形式表示的数字。
筛法,用一个标记数组,所有值初始化为0,从数组下标1开始,如果标记数组值为0,则将从这个数字开始,所以以后由这个数字衍生出去的可以表示的数字,标记为1,如:1的衍生数为2、4、8、16...,一直到10000
代码(1AC):
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 16630 | Accepted: 9324 |
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
Source
Mid-Central USA 1998
存在一种数字,它可以用另一个数和那个数本身各个位数之和表示,比如51可以用39+3+9表示,则要求输出10000以内,所有不能用这种形式表示的数字。
筛法,用一个标记数组,所有值初始化为0,从数组下标1开始,如果标记数组值为0,则将从这个数字开始,所以以后由这个数字衍生出去的可以表示的数字,标记为1,如:1的衍生数为2、4、8、16...,一直到10000
代码(1AC):
#include <cstdio> #include <cstdlib> #include <cstring> #define N 10000 int array[11000]; int list[11000]; int main(void){ int i, j; int top , end; int num, num1, num2; memset(array, 0, sizeof(array)); for (i = 1; i <= N; i++){ if (array[i] == 0){ num = num1 = i; for (; num1 < N;){ num1 = num; while (num){ num1 += num % 10; num /= 10; } num = num1; array[num1] = 1; } } } for (i = 1; i <= N; i++){ if (array[i] == 0){ printf("%d\n", i); } } return 0; }
相关文章推荐
- POJ 1316 Self Numbers (水题)
- POJ1316 Self Numbers【水题】
- Poj 1316 Self Numbers(水题)
- [1316]Self Numbers (水题)POJ
- Poj 1316 Self Numbers(水题)
- poj 1316 Self Numbers
- POJ 1316 Self Numbers 笔记
- POJ 1488 TEX Quotes(我的水题之路——暴水,字符转换)
- POJ 1575 Easier Done Than Said?(我的水题之路——三重标记)
- POJ 2070 Filling Out the Team(我的水题之路——double比较)
- POJ 2665 Trees(我的水题之路——移树,POJ100题啦!)
- POJ 3224 Go for Lab Cup!(我的水题之路——赢的场数最多)
- (简单模拟——筛选法模拟2.2.1)POJ 1316 Self Numbers(生成数、自数)
- POJ 1250 Tanning Salon(我的水题之路——字母表数组标记)
- POJ 1484 Blowing Fuses(我的水题之路——我必须在心中牢记这次惨痛的教训)
- POJ 2141 Message Decowding(我的水题之路——简单解密)
- POJ 2163 Easy Trading(我的水题之路——数组阶段n m的平均值比较)
- POJ 2328 Guessing Game(我的水题之路——猜数字测谎)
- POJ 2562 Primary Arithmetic(我的水题之路——模拟加法进位)
- POJ 2840 Big Clock(我的水题之路——水,钟)