spoj MCUR98(输出数列题)
来源:互联网 发布:什么事大数据 编辑:程序博客网 时间:2024/05/04 12:02
MCUR98 - Self Numbers
Background
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 ben 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.
Problem
Write a program to output all positive self-numbers less than 1000000 in increasing order, one per line.
Input
There is no input.
Output
All positive self-numbers less than 1000000 in increasing order, one per line.
题解:数字题,按条件把是self numbers的标记,最后把不是得输出就好了,
代码:
#include<bits/stdc++.h>#define MAXN 1000005int vis[MAXN];int f(int x){ int ans=x; while(x) { ans+=x%10; x/=10; } return ans;}int main(){ int mark=f(1);vis[mark]=1; for(int i=2;i<=1000000;i++) { if(i%10==0) { mark=f(i); vis[mark]=1; } else { mark+=2; vis[mark]=1;} } for(int i=1;i<1000000;i++) { if(!vis[i]) printf("%d ",i); } return 0;}
- spoj MCUR98(输出数列题)
- 输出数列
- spoj 3196 Divisibility Relation(最大独立集输出方案)
- BZOJ1500: [NOI2005]维修数列 && SPOJ-GSS6 【Splay】
- 输出Fibonacci数列。
- 输出fibnacci数列
- 输出斐波拉契数列
- 逆序输出的数列
- Python 输出斐波纳挈数列
- 螺旋输出数列
- 逆时针输出数列
- SPOJ第二题(素数问题)
- SPOJ第三题(回文数问题)
- SPOJ第四题(倒水问题)
- SPOJ COWPIC(逆序对变形题)
- [SPOJ] 大数竖式计算输出
- 输出数列前40个数
- Python输出一个Fibonacci数列
- iOS--客户端密码加密
- 3种方法快速制作tpk文件
- 样式与include标签的使用及样式的继承和使用
- 不带缓存的I/O和标准(带缓存的)I/O
- test
- spoj MCUR98(输出数列题)
- SpringMVC 实现在页面下载文件(非服务器式下载)
- caffe-yolo 训练
- json总结
- 海康威视技术2面总结
- 快排
- theano第三课(scalar与matrix的求和)
- 提升 iOS 界面的渲染性能
- Android获取内存的不同方法总结