HDU 1058 Humble Numbers (construction?) Enumeration? )

Source: Internet
Author: User

Test instructions

The qualitative factor of a number is only a few of the 2,3,5,7. This is called humble number.

For example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ...

Give N and ask the nth humble number.

Ideas:

The construction of all humble numbers is: (2^a) * (3^b) * (5^c) * (7^d). A,b,c,d is greater than or equal to 0.

X=a+b+c+d represents the number of x humble.

Assuming that the first i-1 humble number has been calculated, the first I humble how to ask?

Must be one of the humble in the first i-1 humble number multiplied by 2 or multiplied by 3 or multiplied by 5 or multiplied by 7.

Well, before enumerating the i-1 humble number, finding the number of i-1 humble and the smallest, then it is the number I humble.

Look at the code

Code:

ll a[5850];intcn=0;intMain () {a[1]=1; CN=1;  while(cn<5842) {ll ans=INF;        ll temp; Rep (I,1, CN) {Temp=a[i]*2;if(TEMP&GT;A[CN]) ans=min (ans,temp); Temp=a[i]*3;if(TEMP&GT;A[CN]) ans=min (ans,temp); Temp=a[i]*5;if(TEMP&GT;A[CN]) ans=min (ans,temp); Temp=a[i]*7;if(TEMP&GT;A[CN]) ans=min (ans,temp); } a[++cn]=ans; }    intN;  while(SCANF ("%d",&N), N) {intt=n%Ten; if(t==1&& n% -!= One) {printf ("The %dst humble number is", N); }        Else if(t==2&& n% -!= A) {printf ("The %dnd humble number is", N); }        Else if(t==3&& n% -!= -) {printf ("The %DRD humble number is", N); }        Else{printf ("The %dth humble number is", N); } printf ("%i64d.\n", A[n]); }    return 0;}

HDU 1058 Humble Numbers (construction?) Enumeration? )

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.