丑数(humble number) hdu 1058 DP
来源:互联网 发布:珠海网络教育 编辑:程序博客网 时间:2024/05/16 10:50
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
#include <stdio.h>#define min(a,b) ((a) < (b) ? (a):(b))#define min4(a,b,c,d) min(min(a,b),min(c,d))int ans[6000];void fun(){ int a2,a3,a5,a7; int n = 1; ans[1] = 1; a2 = a3 = a5 = a7 = 1; while(ans[n] < 2000000000) { ans[++n] = min4(2*ans[a2],3*ans[a3],5*ans[a5],7*ans[a7]); if(ans[n] == 2*ans[a2]) a2 += 1; if(ans[n] == 3*ans[a3]) a3 += 1; if(ans[n] == 5*ans[a5]) a5 += 1; if(ans[n] == 7*ans[a7]) a7 += 1; }}int main(){ int n,ten; fun(); while(~scanf("%d",&n)) { printf("The %d",n); ten = n/10%10; if(n%10 == 1 && ten != 1) printf("st"); else if(n%10 == 2 && ten != 1) printf("nd"); else if(n%10 == 3 && ten != 1) printf("rd"); else printf("th"); printf(" humble number is %d.\n",ans[n]); } return 0;}
0 0
- 丑数(humble number) hdu 1058 DP
- HDU 1058 Humble Numbers && NOJ 1420 丑数 (数位dp)
- 丑数humble number
- HDU 1058 Humble Numbers(丑数,优先队列,STL)
- hdu 1058 Humble Numbers【丑数】
- HDU 丑数 - 1058 Humble Numbers
- 【HDU-1058】Humble Numbers 丑数
- hdu 1058 Humble Numbers 丑数
- HDU 1058 Humble Number DP
- Humble Number 丑数和丑代码
- HDU 1058 Humble Numbers(DP,数)
- HDU 1058 Humble Numbers(DP,数)
- hdu1058 Humble Numbers(丑数) —— dp
- HDU 1058 Humble Number(打表dp)
- HDU 1058 Humble Numbers (动规+寻找丑数问题)
- Humble Numbers(丑数)
- zoj 1095 Humble Numbers(丑数+dp)
- Humble Numbers 丑数 简单dp(思路
- 【Node】node启动过程
- ubuntu 13.04 初探笔记
- OCP-1Z0-新051-61题版本-34
- 2013年度总结
- OCP-1Z0-新051-61题版本-35
- 丑数(humble number) hdu 1058 DP
- OCP-1Z0-新051-61题版本-36
- 【LeetCode】Single Number
- 游戏服务端之AOI概述
- 什么是增量检查点?
- OCP-1Z0-新051-61题版本-37
- OCP-1Z0-新051-61题版本-38
- 设计模式初探-Builder模式
- OCP-1Z0-新051-61题版本-39