POJ 2545

     还是一样的题,,,不解释。不过数据真的太弱了,竟然可以0ms过,,,,看来今天真的很水。。。。。。题目:

Hamming Problem
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5665   Accepted: 2546

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
ac代码:

#include <iostream>
#include <cstdio>
using namespace std;
long long min(long long a,long long b,long long c){
  long long x=a<b?a:b;
  return x<c?x:c;
}
int main(){
  long long prime1,prime2,prime3,order;
  while(~scanf("%lld%lld%lld%lld",&prime1,&prime2,&prime3,&order)){
    long long num[100005];
	num[1]=1;
	int i=1,p1,p2,p3;
	p1=p2=p3=1;
	while(i<=order+1){
	  num[++i]=min(prime1*num[p1],prime2*num[p2],prime3*num[p3]);
	  if(num[i]==prime1*num[p1]) p1++;
	  if(num[i]==prime2*num[p2]) p2++;
	  if(num[i]==prime3*num[p3]) p3++;
	}
	printf("%lld\n",num[order+1]);
  }
  return 0;
}


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