HDU 1058 DP
来源:互联网 发布:java 圆周率计算公式 编辑:程序博客网 时间:2024/05/18 19:41
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21163 Accepted Submission(s): 9254
Problem 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
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 450.The 1000th humble number is 385875.#include<cstdio>#include<iostream>#include<cstring>using namespace std;int min(int a,int b,int c,int d);int dp[6000]={0};int main(){ int f2=1,f3=1,f5=1,f7=1; dp[1]=1; for(int i=2;i<=5845;i++) { dp[i]=dp[i]=min(dp[f2]*2,dp[f3]*3,dp[f5]*5,dp[f7]*7); if(dp[i]==dp[f2]*2) f2++; if(dp[i]==dp[f3]*3) f3++; if(dp[i]==dp[f5]*5) f5++; if(dp[i]==dp[f7]*7) f7++; } int n=0; while(scanf("%d",&n),n) { printf("The "); if(n%10==1&&n%100!=11)printf("%dst",n); else if(n%10==2&&n%100!=12)printf("%dnd",n); else if(n%10==3&&n%100!=13)printf("%drd",n); else printf("%dth",n); printf(" humble number is %d.\n",dp[n]); } return 0;}int min(int a,int b,int c,int d){ if(a<=b&&a<=c&&a<=d) return a; if(b<=a&&b<=c&&b<=d) return b; if(c<=b&&c<=a&&c<=d) return c; if(d<=b&&d<=c&&d<=a) return d;}
0 0
- hdu 1058 DP
- hdu 1058 (DP)
- hdu 1058 dp
- HDU 1058(DP)
- HDU 1058 DP
- hdu 1058(dp)
- hdu 1058 dp解法
- HDU 1058 DP
- HDU 1058 DP
- hdu 1058 Humble Numbers (DP)
- HDU 1058 Humble Number DP
- hdu 1058 Humble Numbers (dp)
- hdu 1058 Humble Numbers(dp)
- hdu 1058 Humble Numbers(DP)
- 【DP】HDU-1058 Humble Numbers
- hdu 1058 Humble Numbers【dp】
- hdu 1058 Humble Numbers(dp)
- HDU 1058 Humble Numbers dp
- java基础学习笔记——collection
- Async Dubbo
- 流氓软件劫持浏览器
- 101个MySQL调试和优化技巧
- java基础学习笔记——Iterattor
- HDU 1058 DP
- servlet之登录页面
- 其他 Demo
- poj 1367 robot(搜索)
- linux 下配置 mysql
- java基础学习笔记——List
- 字符串的KMP算法
- Fragment横竖屏切换问题
- ----------------------------华丽的分割线----------------------------