POJ 1141 Calling extraterrestrial Intelligence Again (timed out)

Source: Internet
Author: User

Calling extraterrestrial Intelligence Again
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 11211 Accepted: 4356

Description

A message from humans to extraterrestrial intelligence is sent through the Arecibo radio telescope in Puerto Rico on the Afternoon of Saturday November 16, 1974. The message consisted of 1679 bits and is meant to is translated to a rectangular picture with x pixels. Since both and numbers, X is the unique possible size of the translated rectangular picture each EDG E of which is longer than 1 pixel. Of course, there is no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic.

We are planning a similar project. Your task in the project was to find the most suitable width and height of the translated rectangular. The term ' most suitable ' is defined as follows. An integer m greater than 4 is given. A positive fraction A/b less than or equal to 1 is also given. The area of the picture should not being greater than M. Both of the width and the height of the translated picture should is prime numbers. The ratio of the width to the height should is less than A/b nor greater than 1. You should maximize the "the" picture under these constraints.

In the other words, you'll receive an integer m and a fraction A/b. It holds that M > 4 and 0 < A/b <= 1. You should find the pair of prime numbers p, q such that PQ <= m and A/b <= p/q <= 1, and furthermore, the PRODUC T PQ takes the maximum value among such pairs of the prime numbers. You should report p and Q as the ' most suitable ' width and height of the translated picture.

Input

The input is a sequence of triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicates the end of the input and should not being treated as D ATA to is processed.

The integers of each input triplet is the integer m, the numerator a, and the denominator B described above, in this Orde R. Assume 4 < M <= 100000 and 1 <= a <= b <= 1000.

Output

The output is a sequence of pairs of positive integers. The i-th output pair corresponds to the i-th input triplet. The integers of each output pair is the width p and the height Q described above, in this order.

Each of the output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output.

Sample Input

5 1 299999 999 9991680 5 161970 1 12002 4 110 0 0

Sample Output

2 2313 31323 7343 4337 53

Source

Japan 2002 Kanazawa
#include <cstdio>#include<cmath>#include<iostream>using namespacestd;#defineN 100001intPrime[n];BOOLCheck[n];intN,a,b,m,tot;intMain () { for(intI=2; i<=n;i++)      if(!Check[i]) {Prime[n++]=i;  for(intj=i*2; j<=n;j+=i) check[j]=1; }     while(SCANF (" %d%d%d", &m,&a,&b) = =3&&m&&a&&b) {        Doubleadivb=a*1.0/b,tmp=0; intANSI,ANSJ;  for(intI=0; i<n;i++){             for(intj=i;j<n;j++){                Doublet1=1.0*prime[i]*Prime[j]; DoubleT2=1.0*prime[i]/Prime[j]; if(t1>tmp&&t1<=m&&t2>=adivb&&t2<=1) {tmp=t1;ansi=i;ansj=J; }}} printf ("%d%d\n", PRIME[ANSI],PRIME[ANSJ]); }    return 0;}

POJ 1141 Calling extraterrestrial Intelligence Again (timed out)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.