Calling Extraterrestrial Intelligence Again

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 5

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

点我找原题
题意很简单,给出m,a,b,求出p,q,要求
p,q是质数
p*q<=m
a/b<=p/q<=1
由于给出的m能达到100000,而p肯定小于q,所以p,q只要到1000就足够了

Problem 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 * 73 pixels. Since both 23 and 73 are prime numbers, 23 * 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 indicated 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

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

Sample Output

2 2
313 313
23 73
43 43
37 53
#include <iostream>#include <cstring>#define N 1005using namespace std;bool tag[1005];int p[1005];void get_prime(){    int cnt=0;   for(int i=2;i<N;i++)    {     if(tag[i]) p[cnt++]=i;     for(int j=0;j<cnt&&p[j]*i<N;j++)     {         tag[i*p[j]]=0;           if(i%p[j]==0) break;        } }}int main(int argc, char *argv[]){ int m,a,b;    int p1,q1,i,j;    int max;  memset(tag,true,sizeof(tag)); get_prime();/*for(i=0;i<170;i++)    {     cout<<p[i]<<endl; }*/

while(cin>>m>>a>>b)   {     if(m==0&&a==0&&b==0) break;     max=0;       for(i=0;i<170;i++)      {         for(j=i;j<170;j++)          {             double c,d;               c=1.0*p[i]/p[j];             d=1.0*a/b;               if(p[i]*p[j]<=m&&c>=d&&c<=1)              {                 if(p[i]*p[j]>max)                  {                     p1=p[i];q1=p[j];                        max=p[i]*p[j];                   }             }         }     }     cout<<p1<<" "<<q1<<endl;    } return 0;}

Calling Extraterrestrial Intelligence Again相关推荐

  1. 413:Calling Extraterrestrial Intelligence Again(翻译 )

    来源:http://noi.openjudge.cn/ch0207/413/ Calling Extraterrestrial Intelligence Again 总时间限制: 1000ms 内存限 ...

  2. HDU 1239 Calling Extraterrestrial Intelligence Again

    题目 http://acm.hdu.edu.cn/showproblem.php?pid=1239 Problem Description A message from humans to extra ...

  3. 08:Calling Extraterrestrial Intelligence AgainMOOC程序设计算法基础期末第八题

    问题表述: A message from humans to extraterrestrial intelligence was sent through the Arecibo radio tele ...

  4. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  5. 【HDOJ】1239 Calling Extraterrestrial Intelligence Again

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

  6. 【筛法求素数】HDU-1239 Calling Extraterrestrial Intelligence Again

    注解 1.首先用筛法求100000以内的素数,并找到其个数. 2.在所有找到的素数中,遍历找一个素数对,满足: (1)二者相乘小于等于m: (2)二者相乘是所有满足条件的素数对中的最大的: (3)二者 ...

  7. POJ 1411 Calling Extraterrestrial Intelligence Again G++ 易超时

    #include <iostream> #include <cstdio> using namespace std; //英语 抄博友程序 博友程序更快 易超时 int pri ...

  8. 大学英语(第六册)复习(原文及全文翻译)——Unit 3 - The Quest For Extraterrestrial Intelligence(搜寻外星人)

    Unit 3 - The Quest For Extraterrestrial Intelligence Are we humans alone in the universe? Or is ther ...

  9. CodeForces刷题C语言:What is for dinner?、Reconnaissance 2、Shell Game、Extra-terrestrial Intelligence、Extra

    记录洛谷刷题c语言QAQ 一.What is for dinner? 题面翻译 题面描述 鲨鱼有 n n n 颗牙齿,分别分布于 m m m 行上,第 i i i 颗牙齿有一个初始活力值 c i c_ ...

最新文章

  1. 优秀Java程序员应该知道的20个实用开源库
  2. 招募 | 《大数据实践课》课程实践企业合作项目
  3. cocos2d JS 自定义事件分发器(接收与传递数据) eventManager
  4. mysql5.5.28安装详最后一个步骤时为啥一直转_mysql5.7.28下载、安装、登陆步骤详解...
  5. Discuz常见小问题-如何快速清除帖子
  6. leetcode -day19 Convert Sorted List to Binary Search Tree
  7. Hibernate 简介(百度)
  8. 随机生成六位不重复数值
  9. git config设置用户名_git从安装到多账户操作一套搞定(二)多账户使用
  10. linux 脚本返回值
  11. 怎么自动选中select中所有option
  12. 拓端tecdat|R语言回归和主成分PCA 回归交叉验证分析预测城市犯罪率
  13. 基于ZStack构建深度学习云平台
  14. c++ string 删除第一个字符_字符串操作的全面总结
  15. Hadoop学习之本地运行hadoop
  16. Tensorflow函数测试之tf.contrib.layers.embed_sequence
  17. 服务器内置usb能否修改为外置,台式机内置的DVD刻录机可以改成外置的USB接口吗?...
  18. python学习之 利用蒙特卡洛方法计算PI值
  19. get-element-by-id转换为getElementById
  20. 简账(开源记账软件)-前端环境简介及部署

热门文章

  1. ENVI-landsat7/8全色与多光谱波段图像融合前,全色波段辐射定标报错指南
  2. python 并行执行_python 串行执行和并行执行实例
  3. 计算机系统要素高清pdf,计算机系统要素:从零开始构建现代计算机[PDF][43.21MB]...
  4. Oracle 聚合实现小计、合计 (GROUP BY ROLLUP)
  5. 【理论-Cisco】策略路由PBR
  6. 最全MySQL面试题和答案
  7. Maven项目Dependencies常见报错及解决方案
  8. 冯绍峰,如果你爱她,记得不要把名字倒过来讲!
  9. 手把手教你做第一个RPA机器人流程
  10. 谨以此文纪念我的2020——不负热爱,砥砺前行