hdu 1058 丑数?
来源:互联网 发布:ug编程自学能学会吗 编辑:程序博客网 时间:2024/05/16 08:36
Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22495 Accepted Submission(s): 9834
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.The 5842nd humble number is 2000000000.humble number从1为"始祖",剩下的所有数,其实都是在此基础上乘以2,3,5,7演化出来的,代码主要语句:f[t]=min(2*f[i],3*f[j],5*f[k],7*f[l]);#include<stdio.h>#include<string.h>#include<stdlib.h>#define min(a,b)(a<b?a:b)int a[5843];int x2,x3,x5,x7;int min4(int a,int b,int c,int d){ int ans1=min(a,b); int ans2=min(c,d); int ans=min(ans1,ans2); if(ans==a) x2++; if(ans==b) x3++; if(ans==c) x5++; if(ans==d) x7++; return ans;}void init(){ x2=x3=x5=x7=1; a[1]=1; for(int i=2;i<=5842;i++) { a[i]=min4(a[x2]*2,a[x3]*3,a[x5]*5,a[x7]*7); }}int main(){ int n; init(); while(scanf("%d",&n),n) { if(n%10==1 && n%100!=11) printf("The %dst humble number is ",n); /// 注意 11,12,13 的输出格式。 else if(n%10==2 && n%100!=12) printf("The %dnd humble number is ",n); else if(n%10==3 && n%100!=13) printf("The %drd humble number is ",n); else printf("The %dth humble number is ",n); printf("%d.\n",a[n]); } return 0;}
0 0
- hdu 1058 丑数?
- hdu 1058 Humble Numbers【丑数】
- HDU 丑数 - 1058 Humble Numbers
- 【HDU-1058】Humble Numbers 丑数
- HDU 1058||Uva 136 丑数
- hdu 1058 Humble Numbers 丑数
- hdu 3199 丑数2
- 丑数(humble number) hdu 1058 DP
- HDU 1058 Humble Numbers (动规+寻找丑数问题)
- HDU 1058 Humble Numbers && NOJ 1420 丑数 (数位dp)
- HDu 1058 丑数 (打表||DP,好题啊!!!)
- HDU 1058 Humble Numbers(丑数,优先队列,STL)
- 1058 丑数
- HDU 3199 Hamming Problem 丑数
- 丑数
- 丑数
- 丑数
- 丑数
- 观察者模式
- 机器学习之单变量线性回归(Linear Regression with One Variable)
- /*外接矩形部分*/
- 诡异的Android开发中EditText键盘弹出后被遮盖的bug
- 【Linux C 王者归来】【第四章】【指针与字符串】
- hdu 1058 丑数?
- android 语音合成的简单实现
- 机器学习之多变量线性回归(Linear Regression with multiple variables)
- iOS开发工具箱[003]:图片可随表往下拖动自动放大的效果
- 如何教女朋友一起编程
- 电动机绕组的接线舞曲
- java---Serializable(序列化)
- opencv中使用bp神经网络
- 跟着编程之美学算法——最长递增子序列