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

Description

A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted of 1679 bits and was meant to be translated to a rectangular picture with 23 x 73 pixels. Since both 23 and 73 are prime numbers, 23 x 73 is the unique possible size of the translated rectangular picture each edge of which is longer than 1 pixel. Of course, there was 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 is to find the most suitable width and height of the translated rectangular picture. 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 be greater than m. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than a/b nor greater than 1. You should maximize the area of the picture under these constraints.

In other words, you will 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 product pq takes the maximum value among such pairs of two 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 at most 2000 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 be treated as data to be processed.

The integers of each input triplet are the integer m, the numerator a, and the denominator b described above, in this order. You may 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 are the width p and the height q described above, in this order.

Each 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

  1. 5 1 2
  2. 99999 999 999
  3. 1680 5 16
  4. 1970 1 1
  5. 2002 4 11
  6. 0 0 0

Sample Output

  1. 2 2
  2. 313 313
  3. 23 73
  4. 43 43
  5. 37 53

Source

 
  1. #include<cstdio>
  2. #include<cmath>
  3. #include<iostream>
  4. using namespace std;
  5. #define N 100001
  6. int prime[N];
  7. bool check[N];
  8. int n,a,b,m,tot;
  9. int main(){
  10. for(int i=;i<=N;i++)
  11. if(!check[i]){
  12. prime[n++]=i;
  13. for(int j=i*;j<=N;j+=i)
  14. check[j]=;
  15. }
  16. while(scanf("%d %d %d",&m,&a,&b)==&&m&&a&&b){
  17. double adivb=a*1.0/b,tmp=;
  18. int ansi,ansj;
  19. for(int i=;i<n;i++){
  20. for(int j=i;j<n;j++){
  21. double t1=1.0*prime[i]*prime[j];
  22. double t2=1.0*prime[i]/prime[j];
  23. if(t1>tmp&&t1<=m&&t2>=adivb&&t2<=){
  24. tmp=t1;ansi=i;ansj=j;
  25. }
  26. }
  27. }
  28. printf("%d %d\n",prime[ansi],prime[ansj]);
  29. }
  30. return ;
  31. }

poj 1411 Calling Extraterrestrial Intelligence Again(超时)的更多相关文章

  1. poj 1411 Calling Extraterrestrial Intelligence Again

    题意:给你数m,a,b,假设有数p,q,满足p*q<=m同时a/b<=p/q<=1,求当p*q最大的p和q的值 方法:暴力枚举 -_-|| and 优化范围 我们可以注意到在某一个m ...

  2. hdu 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)

    Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  3. HDUOJ-----(1329)Calling Extraterrestrial Intelligence Again

    Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  4. Calling Extraterrestrial Intelligence Again POJ 1411

    题目链接:http://poj.org/problem?id=1411 题目大意:找两个素数p,q满足a/b<=p/q<=1 且p*q<=m,求p*q最大的一组素数对. 第一次想的是 ...

  5. 【HDOJ】1239 Calling Extraterrestrial Intelligence Again

    这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来. #include <stdio.h> #include <string.h> #include <ma ...

  6. 【noi 2.7_413】Calling Extraterrestrial Intelligence Again(算法效率--线性筛素数+二分+测时)

    题意:给3个数M,A,B,求两个质数P,Q.使其满足P*Q<=M且A/B<=P/Q<=1,并使P*Q最大.输入若干行以0,0,0结尾. 解法:先线性筛出素数表,再枚举出P,二分出对应 ...

  7. 穷举(四):POJ上的两道穷举例题POJ 1411和POJ 1753

    下面给出两道POJ上的问题,看如何用穷举法解决. [例9]Calling Extraterrestrial Intelligence Again(POJ 1411) Description A mes ...

  8. POJ 1411

    #include<iostream> #include<stdio.h> #include<math.h> #define MAXN 50000 using nam ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. 一些arcgis符号库干货

    分享一些arcgis符号库干货,自己也可以参考网上的教程自己做,但尽量要符合标准规范. 下面是一些符号示例(并不一定是官方标准的): 土地利用总体规划图 水土保持图 1:5万土地利用现状 1:1万地形 ...

  2. Azure SQL Database 时间点还原(Point in Time Restore)功能

      微软中国TechNet 7 Oct 2014 9:17 PM Comments 0 Likes 原文地址:http://blogs.technet.com/b/azuretw/archive/20 ...

  3. Android-adb 常用命令 和 sqlite

    Android开发环境中,ADB是我们进行Android开发经常要用的调试工具,它的使用当然是我们Android开发者必须要掌握的. ADB概述 Android Debug Bridge,Androi ...

  4. Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"

    Spring注入Action使用Json错误:org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: ...

  5. Eclipse环境下配置spket中ExtJS5.0提示

    使用eclipse编写extjs时,一定会用到spket这个插件,spket可以单独当作ide使用,也可以当作eclipse插件使用,我这里是当作eclipse的插件使用的,下面来一步步图解说明如何配 ...

  6. iOS UI 之UILable

    @interface ViewController : UIViewController @property (strong,nonatomic) UILabel *aLable; @property ...

  7. 如何改进iOS App的离线使用体验

    App Store中的App分析 App已经与我们形影不离了,不管在地铁上.公交上还是在会场你总能看到很多人拿出来手机,刷一刷微博,看看新闻. 据不完全统计有近一半的用户在非Wifi环境打开App,以 ...

  8. Java集合 之 List 集合

    1.什么是Lsit集合? List集合是一种元素有序的,可重复的集合,集合中每个元素都有自己的元素索引.List集合允许可重复的元素,可以通过索引来访问指定位置的元素. 2.Java8改进的List接 ...

  9. 通过JAVA反射,调用未知类的类方法

    下面是一个比较简单的通过JAVA的反射机制调用已知方法的例子 package com.togeek.mvntest; import java.lang.reflect.InvocationTarget ...

  10. 获取byte数组的实际使用长度

    背景:byte.length只能获取到初始化的byte数组长度,而不是实际使用的长度,因此想要获取到实际的使用长度只能靠其他方法实现. 方法一: public class ByteActualLeng ...