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.
In the single line of input file there are space-separated integers p1 p2 p3 i. Process to the end of file.
7 13 19 100
26590291 |
首先非常B4挂木马的坏孩子,在我搜索答案的时候居然有人挂马,可恶的人儿...........................
不过最后还是学会了这种"打表"的方法....
- #include<iostream>
- #include <algorithm>
- using namespace std;
- int len=2,l,l1,l2,l3,ll[3];
- long long *a;
- int main()
- {
- int n,k,i;
- long long min;
- while(cin>>ll[0]>>ll[1]>>ll[2]>>k)
- {
- a=new long long[k+1];
- sort(ll,ll+3);
- a[0]=1;
- len=1;
- l1=l2=l3=0;
- while(len<=k)
- {
- min=a[l1]*ll[0];
- l=1;
- if(a[l2]*ll[1]<min) min=a[l2]*ll[1],l=2;
- if(a[l3]*ll[2]<min) min=a[l3]*ll[2],l=3;
- if(a[len-1]!=min)
- a[len++]=min;
- if(l==1) l1++;
- if(l==2) l2++;
- if(l==3) l3++;
- }
- cout<<a[k]<<endl;
- delete []a;
- }
- }