POJ 2545 Hamming Problem

64 篇文章 0 订阅
54 篇文章 0 订阅
 

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.

Process to the end of file.


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

  首先非常B4挂木马的坏孩子,在我搜索答案的时候居然有人挂马,可恶的人儿...........................

不过最后还是学会了这种"打表"的方法....

  1. #include<iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int len=2,l,l1,l2,l3,ll[3];
  5. long long *a;
  6. int main()
  7. {
  8.     int n,k,i;
  9.          long long min;
  10.     while(cin>>ll[0]>>ll[1]>>ll[2]>>k)
  11.         {
  12.             a=new long long[k+1];
  13.             sort(ll,ll+3);
  14.             a[0]=1;
  15.             len=1;
  16.             l1=l2=l3=0;
  17.             while(len<=k)
  18.                 {
  19.                     min=a[l1]*ll[0];
  20.                     l=1;
  21.                     if(a[l2]*ll[1]<min) min=a[l2]*ll[1],l=2;
  22.                     if(a[l3]*ll[2]<min) min=a[l3]*ll[2],l=3;
  23.                     if(a[len-1]!=min)
  24.                         a[len++]=min;
  25.                     if(l==1) l1++;
  26.                     if(l==2) l2++;
  27.                     if(l==3) l3++;
  28.                 }
  29.             cout<<a[k]<<endl;
  30.             delete []a;
  31.         }
  32. }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值