HDU 1058 Humble Numbers

Source: Internet
Author: User

Humble Numbers



Problem Descriptiona 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

Inputthe 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.

Outputfor 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 Input1234111213212223100100058420

Sample outputthe 1st Humble number is 1.The 2nd humble number is 2.The 3rd humble number are 3.The 4th humble number is 4.T He 11th humble number is 12.The 12th humble number is 14.The 13th humble number was 15.The 21st humble number is 28.The 22n D Humble number is 30.The 23rd humble number are 32.The 100th humble number is 450.The 1000th humble number is 385875.The 5 842nd humble number is 2000000000.
1#include <cstdio>2#include <string>3#include <cstring>4#include <map>5 using namespacestd;6 7 intdp[6000];8 intMinintXintYintZintW)9 {Ten     intTemp1=x<y?x:y; One     intTemp2=temp1<z?temp1:z; A     returnTemp2<w?temp2:w; - } -  the intMain () - { -     //freopen ("In.txt", "R", stdin); -     intt[8],n; +dp[1]=1; -t[7]=t[2]=t[3]=t[5]=1; +      for(intI=2; i<=5842; i++) A     { atDp[i]=min (dp[t[2]]*2, dp[t[3]]*3, dp[t[5]]*5, dp[t[7]]*7); -          while(dp[t[2]]*2<=dp[i]) t[2]++; -          while(dp[t[3]]*3<=dp[i]) t[3]++; -          while(dp[t[5]]*5<=dp[i]) t[5]++; -          while(dp[t[7]]*7<=dp[i]) t[7]++; -     } in      while(SCANF ("%d",&N), N) -     { toprintf"The %d", n); +         if(n%Ten==1&&n% -!= One) -printf"St"); the         Else if(n%Ten==2&&n% -!= A) *printf"nd"); $         Else if(n%Ten==3&&n% -!= -)Panax Notoginsengprintf"Rd"); -         Else theprintf"th"); +printf"Humble number is%d.\n", Dp[n]); A     } the     return 0; +}

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.