POJ 1316 Self Numbers 筛选模拟
2015-08-07 19:45
190 查看
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
AC代码:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22203 | Accepted: 12494 |
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
AC代码:
#include <iostream> #include <cmath> #include <cstring> #include <algorithm> using namespace std; int main(){ int i,j,k,m,n; int a[10050]; memset(a,1,sizeof(a)); for(i=0;i<10;i++) for(j=0;j<10;j++) for(m=0;m<10;m++) for(n=0;n<10;n++) a[1001*i+101*j+11*m+2*n]=0; for(i=0;i<=10000;++i) if(a[i])cout<<i<<'\12'; return 0; }
相关文章推荐
- POJ2299-Ultra-QuickSort 解题心得
- Log4j.properties配置详解
- HDU 1406 完数
- 认识Service
- QT下实现将图片从一个文件拷贝到另一个文件夹
- Windows下命令安装MySQL.zip压缩包以及修改MySQL密码
- UOJ #5. 【NOI2014】动物园 扩大KMP
- POJ 1922 Ride to School 简单模拟
- Codeforces Gym 100418K Cards 暴力打表
- Scala学习笔记-14
- 外键查询及删除
- swirl 6: Subsetting Vectors
- hdu 5355 Cake dfs暴搜 构造
- HashMap和HashSet的区别
- HDU 1201 18岁生日
- POJ 2017 Speed Limit 简单模拟
- sizeof运算符
- Java程序设计之Constructor
- Ubuntu 14.10 下设置静态IP
- 请听一个故事------>百度员工离职总结:如何做个好员工