POJ 1316 Self Numbers

题目链接:

http://poj.org/problem?id=1316

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

1
3
5
7
9
20
31
42
53
64
 |
 |       <-- a lot more numbers
 |
9903
9914
9925
9927
9938
9949
9960
9971
9982
9993Hint题意:就是让你求1到10000以内所有的自私数,什么叫自私数?如果一个数不能分解为另一个数和那个数各位数字之和,它就是一个"自私数",举个例子,57可以是51+5+1来得到,那么57就不是自私数。那么100以内的自私数是:1,3,5,7,9,20,31,42,53,64,75,86和97。

题解:直接把1到10000的非自私数打表存起来就行了。

代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
const int maxn = 1e4;
int a[maxn];
int main()
{
    met(a,0);
    for(int i=1;i<maxn;i++)
    {
        int num=i;
        int sum=num;
        while(num)
        {
            sum+=num%10;
            num/=10;
        }
        if(sum<maxn)
            a[sum]=1;
    }
    for(int i=1;i<maxn;i++)
    {
        if(a[i]==0)
            printf("%d\n",i);
    }
}

  

 
时间: 2024-12-24 00:47:23

POJ 1316 Self Numbers的相关文章

poj 3252 Round Numbers 【推导&#183;排列组合】

以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-Rn[0,start-1] 所以关键是给定一个X,求出Rn[0,X] 现在假设X=10100100  这个X的二进制总共是8位,任何一个小于8位的二进制都小于X 第一部分,求出长度为[0,7]区间内的二进制是RoundNumber的个数  对于一个长度为Len的二进制(最高位为1),如何求出他的Rou

POJ 1715 Hexadecimal Numbers 组合数学

POJ 1715 Hexadecimal Numbers 组合数学 题目地址 题意: 一个十六进制,最多8位而且每一位都不能重复,求所有符合的数中第n大的数.注意不能有前导0. 分析: 可以发现,第i位的任何一个取值,都有P(unused, i - 1)个数字串,只要从高位向低位,从F到1找过去,看第n个是否在这个区间里面,如果没有的话就把那位置为0,然后找下一位就行了. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1715.c

poj 1715 Hexadecimal Numbers 排列组合

1 /** 2 大意: 给定16进制数的16个字母,,求第k大的数,,要求数的长度最大为8.,并且每个数互不相同. 3 思路: 从高到低挨个枚举,每一位能组成的排列数 ,拿最高位来说,能做成的排列数为15*A(15,len-i) 4 第二位 A(14,len-2)..这样就可以找到k大的数的长度 5 接下来 .找第k大的数.同上理 ,挨个枚举每一位即可..若加上该位的排列数大于k,则该位就是这个数,继续枚举下一位 6 **/ 7 8 /** 大神思路 9 首先确定数字串的长度Len:从大到小枚举

POJ 3252 Round Numbers 数学题解

Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets

POJ 3641 Pseudoprime numbers 米勒罗宾算法

链接:http://poj.org/problem?id=3641 题意:由费马小定理可得,对于素数p,a^p = a (mod p),但是对于某些非素数p,也有比较小的可能满足a^p = a (mod p),如果满足,则称p是a条件下的伪素数,现给出p,a,问p是不是a条件的伪素数. 思路:首先用米勒 罗宾判断p是不是素数,如果不是,判断a^p = a (mod p)是否成立. 代码: #include <iostream> #include <cstdio> #include

poj 3641 Pseudoprime numbers Miller_Rabin测素裸题

题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为poj不能用srand()...之后各种WA..因为里面(a,p) ?= 1不一定互素,即这时Fermat定理的性质并不能直接用欧拉定理来判定..即 a^(p-1)%p = 1判断是错误的..作的 #include<iostream> #include<cstdio> #include&l

POJ 1385-Binary Stirling Numbers(判断第二类斯特林数的奇偶性)

Binary Stirling Numbers Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1430 Appoint description:  System Crawler  (2015-04-22) Description The Stirling number of the second kind S(n, m) stands

poj 1338 Ugly Numbers(丑数模拟)

转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338">http://poj.org/problem?id=1338 Description Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10

POJ 1320 Street Numbers 【佩尔方程】

任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3181   Accepted: 1776 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the