HDU 1058 Humble Numbers

Source: Internet
Author: User

Description

A number whose only prime factors be 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, ten,, +, (+), A, ten, A, ten, ten, ... shows the first humble numbers.

Write a program to find and print the nth element in this sequence

Input

The input consists of one or more test cases. Each test case consists the one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for N.

Output

For each test case, print one line saying "The nth humble number is number." Depending on the value of n, the correct suffix "st", "nd", "ts", or "th" for the ordinal number nth have to is used like I T is shown in the sample output.

Sample Input

1234111213212223100100058420

Sample Output

The 1st humble number is 1.The 2nd humble number is 2.The 3rd humble number are 3.The 4th humble number is 4.The 11th HUMBL E number is 12.The 12th humble number are 14.The 13th humble number is 15.The 21st humble number is 28.The 22nd humble numb ER is 30.The 23rd humble number is 32.The 100th humble number are 450.The 1000th humble number is 385875.The 5842nd humble Number is 2000000000. Test instructions: There is a number of the qualitative factor is any one or more of the 2,3,5,7, then it is humble number, the number of nth humble. Analysis: If a humble number, then it is certainly a multiple of 2,3,5,7, then A[k]=min (2*B2,3*B3,5*B5,7*B7), and B2,b3,b5,b7 constantly updated, so in order to arrange the
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespacestd;inta[5850]= {0,1};intMain () {intk=1, N; intB2,b3,b5,b7; B2=b3=b5=b7=1;  while(k<=5842) {a[++k]=min (2*a[b2],min (3*a[b3],min (5*A[B5],7*A[b7])); if(a[k]==2*a[b2]) B2++; if(a[k]==3*a[b3]) B3++; if(a[k]==5*a[b5]) B5++; if(a[k]==7*A[b7]) B7++; }     while(~SCANF ("%d",&N), N) {if(n%Ten==1&&n% -!= One) printf ("The %dst humble number is%d.\n", N,a[n]); Else if(n%Ten==2&&n% -!= A) printf ("The %dnd humble number is%d.\n", N,a[n]); Else if(n%Ten==3&&n% -!= -) printf ("The %DRD humble number is%d.\n", N,a[n]); Elseprintf ("The %dth humble number is%d.\n", N,a[n]); }    return 0;}
View Code

HDU 1058 Humble 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.