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.
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; }