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. 2. Trailing Zeros【easy】

    2. Trailing Zeros[easy] Write an algorithm which computes the number of trailing zeros in n factoria ...

  2. win7安装RabbitMQ

    1.下载并安装erlang http://www.erlang.org/downloads 2.下载并安装RabbitMQ http://www.rabbitmq.com/install-window ...

  3. angular总结控制器的三种主要职责: 为应用中的模型设置初始状态 通过$scope对象把数据模型或函数行为暴露给视图 监视模型的变化,做出相应的动作

    m1.双向数据绑定: <body> <div ng-app ng-init="user.name='world'"> <h1>使用NG实现双边数 ...

  4. shell脚本中多命令单行执行_转

    多命令一起执行 如果希望把几个命令合在一起执行, shell提供了两种方法.既可以在当前shell也可以在子shell中执行一组命令. 对{}和()而言, 括号中的重定向符只影响该条命令, 而括号外的 ...

  5. php windows 扩展redis

    一:客户端安装redis (1)下载地址:https://github.com/dmajkic/redis/downloads 根据电脑是多少位的使用对应的文件,如我的是64bit,那么我就选择64b ...

  6. Android实现录屏直播(二)需求才是硬道理之产品功能调研

    请尊重分享成果,转载请注明出处,本文来自Coder包子哥,原文链接:http://blog.csdn.net/zxccxzzxz/article/details/54254244 前面的Android ...

  7. hdu1754(splay tree 单点更新,成段查询)

    题意就是简单的点更新,成段查询. splay tree 果真是常数比较大的log(n)操作. 比线段树还慢了这么多. // // main.cpp // splay // // Created by ...

  8. N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)

    N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:% ...

  9. grafana-----Annotation

    注释提供了一个方法,在丰富的活动中做个标志点.当你鼠标移到这个注释上,你可以得到title,tags,和text information的事件. Queries 注释事件获得是通过一个注释查询.打开d ...

  10. Architectural Styles and the Design of Network-based Software Architectures

    w Architectural Styles and the Design of Network-based Software Architectures  http://www.ics.uci.ed ...