Hamming Problem(hdu3199)

Hamming Problem

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

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
 
 
本来以为会超时的,,哈哈 o(∩_∩)o 过了。。。。
 
 
 
详见代码吧,
#include<stdio.h>
#include<string.h>
#define min(x,y) ((x)<(y)?(x):(y))//一定要打括号。。。
__int64 num[100000];
int main()
{
    int i,p1,p2,p3;    
    int a,b,c;
    int m;
    
    while(scanf("%d%d%d%d",&a,&b,&c,&i)!=EOF)
    {

        memset(num,0,sizeof(num));
        p1=p2=p3=0;
        num[0]=1;
        for(m=0;m<=i;)
        {
            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
",num[i]);
    }
    return 0;
}
 不解释了。。。
 
 
原文地址:https://www.cnblogs.com/yuyixingkong/p/3422190.html