poj2545 Hamming Problem----暴力

Hamming Problem
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5917   Accepted: 2692

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

Source

Northeastern Europe 2000, Far-Eastern Subregion
 
脑残,竟然不知道要这么暴力~
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
#define ll __int64
using namespace std;
ll num[100010];
ll min(ll a,ll b,ll c)
{
    ll x=a<b?a:b;
    x=x<c?x:c;
    return x;
}
int main()
{
    ll p[3],cnt;
    while(scanf("%I64d%I64d%I64d%I64d",&p[0],&p[1],&p[2],&cnt)!=EOF)
    {
        num[1]=1;
        int i=1;
        int y1=1,y2=1,y3=1;
        while(i<=cnt+1)
        {
            num[++i]=min(p[0]*num[y1],p[1]*num[y2],p[2]*num[y3]);
            if(num[i]==p[0]*num[y1]) y1++;
            if(num[i]==p[1]*num[y2]) y2++;
            if(num[i]==p[2]*num[y3]) y3++;
        }
        cout<<num[cnt+1]<<endl;
    }
}

你可能感兴趣的:(File,Integer,less,input,output,Numbers)