Hamming Problem

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1305 Accepted Submission(s): 583

Problem Description
For each three prime numbers p1, p2 and p3, let's define Hamming sequence Hi(p1, p2, p3), i=1, ... as containing in increasing order all the natural numbers whose only prime divisors are p1, p2 or p3.

For example, H(2, 3, 5) = 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, ...

So H5(2, 3, 5)=6.

Input
In the single line of input file there are space-separated integers p1 p2 p3 i.


Output
The output file must contain the single integer - Hi(p1, p2, p3). All numbers in input and output are less than 10^18.


Sample Input

7 13 19 100

Sample Output

26590291

Source
Northeastern Europe 2000 - Far-Eastern Subregion


解析:本题是[HDU 1058 Humble Numbers](http://www.cnblogs.com/inmoonlight/p/6030949.html)的升级版,2、3、5变成了p1、p2、p3。不过原理是相同的,都是运用DP的思想。因为题目有说明所有输入输出小于10^18,我们可以用2、3、5来得到最大可能出现的下标。经过测试,第一个大于或等于10^18的数下标为10916,因而数组的大小最小为10917。


```
#include
#include
#define ll long long
using namespace std;

ll res[11000];

void solve(int a, int b, int c, int n)

{

res[0] = 1;

int p1 = 0, p2 = 0, p3 = 0;

for(int i = 1; i <= n; ++i){

res[i] = min(res[p1]a, min(res[p2]b, res[p3]c));

if(res[i] == res[p1]
a) ++p1;

if(res[i] == res[p2]b) ++p2;

if(res[i] == res[p3]
c) ++p3;

}

printf("%I64d\n", res[n]);

}

int main()

{

int a, b, c, n;

while(~scanf("%d%d%d%d", &a, &b, &c, &n)){

solve(a, b, c, n);

}

return 0;

}

HDU 3199 Hamming Problem的更多相关文章

  1. hdu 3199 Hamming Problem(构造?枚举?)

    题意: For each three prime numbers p1, p2 and p3, let's define Hamming sequence Hi(p1, p2, p3), i=1, . ...

  2. Hamming Problem(hdu3199)

    Hamming Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  4. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  5. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. hdu 5105 Math Problem(数学)

    pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...

  7. Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)

    题目链接: Hdu  5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...

  8. 网络流 HDU 3549 Flow Problem

    网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...

  9. hdu 4712 Hamming Distance(随机函数暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

随机推荐

  1. 28. Implement strStr()【easy】

    28. Implement strStr()[easy] Implement strStr(). Returns the index of the first occurrence of needle ...

  2. JavaScript之引用类型

    js中的引用类型和其他语言中类的概念很相似,但并不一样. 引用类型是一种数据结构,就像房子的骨架,承载着数据和功能的衔接. 而对象,则是引用类型的具体实现,即实例. var person = new ...

  3. python抓取新浪首页的小例子

    参考 廖雪峰的python教程:http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0 ...

  4. 设置一个label显示多种颜色,多种字体大小

    UILabel* label = [[UILabel alloc] init]; label.frame = CGRectMake(0, 100, 200, 100); label.textColor ...

  5. bonjour的使用

    os中,bonjour是一个零配置的网络服务分发服务器与客户端.   在使用bonour之前你应该明白的是,bonjour并不负责数据传输,只负责发布服务与检索服务,并在客户端获取服务端的信息.   ...

  6. Shiro学习(总结)

    声明:本文原文地址:http://www.iteye.com/blogs/subjects/shiro 感谢开涛提供的博文,让我学到了非常多.在这里由衷的感谢你,同一时候我强烈的推荐开涛的博文.他的博 ...

  7. DataUml Design 教程4-代码生成

            DataUml Design 生成代码非常灵活,它是基于模板形式生成代码,如果不懂类结构的话写模型就比较困难了.这里我只讲解下如何生成代码,代码模板规则下一节将介绍.        1 ...

  8. GoWeb编程之多路复用

    GoWeb编程多路复用 在web编程中,比如我们要一个Url对应一个处理函数,或者一个页面对应一个静态文件,这些都需要进行处理,这个时候就是我们多路复用派上用场了. package main impo ...

  9. Problem #3263 丽娃河的狼人传说 区间满足灯数,r排序后贪心。

    丽娃河的狼人传说 Time limit per test: 1.0 seconds Time limit all tests: 1.0 seconds Memory limit: megabytes ...

  10. Sublime 中 SFTP插件的使用

    首先说明的是Sumblime Text 3,下载安装后,打开软件, 按下Ctrl+Shift+P调出命令面板, 按回车键后弹出下面的 然后 点击左上角的 文件 >SFTP/FTP > Se ...