HDU 1128 Self Numbers

Source: Internet
Author: User

Self Numbers

Time limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6960 Accepted Submission (s): 3047


Problem DescriptionIn 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called Self-numbers. For any positive integer n, define D (n) to is n plus the sum of the digits of N. (the D stands for digitadition, a term Co Ined by Kaprekar.) For example, D (75) = 75 + 7 + 5 = 87. Given any positive an 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 a, the next number is a + 3 + 3 =, the next is the 3 + 9 = Wuyi, the next is 51 + 5 + 1 = 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, am a generator of a, is a generator of a, Wuyi is a generator of the. Some numbers had more than one generator:for example, 101 had both generators, and 100. A number with no generators is a self-number. There is thirteen self-numbers less than 100:1, 3, 5, 7, 9, (+), 97,,, and.


Write a program to output all positive self-numbers less than or equal 1000000 in increasing order, one per line.

Sample output135792031425364| | <--a lot more numbers|9903991499259927993899499960997199829993| | |

Sourcemid-central USA 1998

Recommendeddy | We have carefully selected several similar problems for you:1124 1157 1164 1113 1073 This problem does not have input, look at the meaning of the topic to write this array, direct screening violence to hit the table just fine. Test instructions: Output This string of numbers, each number within 1000000, plus each of its own digits, can produce another number, but some numbers, can not be generated by this, please output these numbers. Attached code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intvisit[1000001];6 intxxintN)7 {8     intsum=0;9      while(n!=0)Ten     { Onesum+=n%Ten; AN/=Ten; -     } -     returnsum; the } - intMain () - { -     inti,j,sum; +memset (Visit,1,sizeof(visit)); -      for(i=1; i<=1000000; i++)//Direct violence to play the table +     { Asum=i; atsum+=xx (i); -visit[sum]=0;//numbers that do not need to appear are labeled 0 -     } -      for(i =1; i<=1000000; i++) -     { -         if(Visit[i]) inprintf"%d\n", i); -     } to     return 0; +}

HDU 1128 Self Numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.