Hamming 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
//任何一个合数都可以写成几个质数相乘的形式。 //其中每个质数都是这个合数的因数, //叫做这个合数的分解质因数。分解质因数只针对合数 //H序列里的质数只有p1,p2,p3,剩下的都是合数 //反过来想就是由(p1,p2,p3)中任意n个组合相乘 //数据过大,勿暴力!用打表法   //可以用__int64;  #include <stdio.h>  #include <string.h>  #define min(x,y) ((x)<(y)?(x):(y))  __int64 num[100000]; int main() { int a,b,c; int p1,p2,p3,i;  while(scanf("%d%d%d%d",&a,&b,&c,&i)) { int m; memset(num,0,sizeof(num));//初始化num[]; p1=p2=p3=0; num[0]=1; for(m=1;m<=i;m++) { num[m]=min(min(a*num[p1],b*num[p2]),c*num[p3]);     if(num[m]==a*num[p1])     p1++;     if(num[m]==b*num[p2])     p2++;     if(num[m]==c*num[p3])     p3++;     //打表printf("%d",num[m]);       } printf("%I64d\n",num[i]); } return 0; }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值