HDU3199 Hamming Problem 【数论】

Hamming Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 703    Accepted Submission(s): 289


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

#include <stdio.h>
#define maxn 10000

__int64 dp[maxn] = {1, 1};
__int64 a0, b0, c0, a, b, c;

__int64 min(__int64 u, __int64 v, __int64 x)
{
    __int64 tmp = u;
    if(tmp > v) tmp = v;
    if(tmp > x) tmp = x;

    if(tmp == u) ++a;
    if(tmp == v) ++b;
    if(tmp == x) ++c;
    
    return tmp;
}

int main()
{
    __int64 i, n;
    while(scanf("%I64d%I64d%I64d%I64d", &a0, &b0, &c0, &n) != EOF){
        a = b = c = 0; dp[0] = 1;
        for(i = 1; i <= n; ++i)
            dp[i] = min(dp[a]*a0, dp[b]*b0, dp[c]*c0);
        printf("%I64d\n", dp[n]);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值