A-humble numbers

Source: Internet
Author: User
Time limit:1000 ms Memory limit:32768kb 64bit Io format:% I64d & % i64usubmit status practice HDU 1058

Description

A number whose only prime factors are 2, 3, 5 or 7 is called a humble number. the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27 ,... shows the first 20 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 of 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", "RD ", or "th" for the ordinal number nth has to be used like it 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 is 3.The 4th humble number is 4.The 11th humble number is 12.the 12th humble number is 14.The 13th humble number is 15.the 21st humble number is 28.The 22nd humble number is 30.The 23rd humble number is 32.the 100th humble number is 2.16.the 1000th humble number is 255.75.the 5842nd humble number is 2000000000.
1 # include <cstdio> 2 # include <string. h> 3 using namespace STD; 4 const int maxn = 5843; 5 Int num2 = 0, num3 = 0, num5 = 0, num7 = 0; 6 long s [maxn]; 7 void sort () // The sort function is used to evaluate the 8 {9 s [0] = 1; 10 s [num2] = 1, s [num3] = 1, s [num5] = 1; 11 long min = s [num2] * 2; 12 INT num2 = 0, num3 = 0, num5 = 0, num7 = 0; 13 for (INT I = 1; I <5843; I ++) 14 {15 16 min = s [num2] * 2; 17 if (min> S [num3] * 3) 18 min = s [num3] * 3; 19 if (min> S [num5] * 5) 20 Min = s [num5] * 5; 21 if (min> S [num7] * 7) 22 min = s [num7] * 7; 23 s [I] = min; 24 // printf ("% d", s [I]); 25 // printf ("% d", min ); 26 if (min = s [num2] * 2) 27 num2 ++; 28 If (min = s [num3] * 3) 29 num3 ++; 30 if (min = s [num5] * 5) 31 num5 ++; 32 If (min = s [num7] * 7) 33 num7 ++; 34} 35} 36 int main () 37 {38 int N; 39 sort (); 40 while (scanf ("% d", & N )! = EOF & N) 41 {42 if (N % 10 = 1 & N % 100! = 11 & n! = 11) // card at N % 100! = 11 and 12, 13 here, wa a few times! 43 printf ("the % DST humble number is", n); 44 else if (N % 10 = 2 & N % 100! = 12 & n! = 12) 45 printf ("the % DND humble number is", n); 46 else if (N % 10 = 3 & N % 100! = 13 & n! = 13) 47 printf ("the % DRD humble number is", n); 48 else printf ("the % DTH humble number is", N ); 49 printf ("% LLD. \ n ", s [n-1]); 50} 51 return 0; 52}

 

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.