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 <stdio.h>
#include <math.h>
#include <stdlib.h>
bool isprime(int num)
{
for(int i=;i<=(int)sqrt((double)num);i++)
if(num%i==)
return false;
return true;
}
int main()
{
int m,a,b,p,q,num[]={},i,j;
for(i=,j=;i<;i++)
if(isprime(i)) num[j++]=i;
while(scanf("%d%d%d",&m,&a,&b)==)
{
//printf("%lf\n",(double)a/b);
int max=,_p,_q;
if(m==&&a==&&b==) break;
for(p=;p<j;p++)
for(q=p;q<j;q++)
if(num[p]*num[q]<=m && (double)a/b <= (double)num[p]/num[q] && (double)num[p]/num[q]<=)//num数组为int型,对除法前一个元素用强制类型转换
if(num[p]*num[q]>max)
{max=num[p]*num[q];_p=num[p];_q=num[q];}
printf("%d %d\n",_p,_q);
}
system("pause>nul");
return ;
}

最新文章

  1. Spring学习记录(四)---bean之间的关系:继承、依赖
  2. 函数指针_typedef
  3. 探秘重编译(Recompilations)(1/2)
  4. appium 常用api介绍(2)
  5. Python日志输出——logging模块
  6. Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心
  7. cocoaPods教程
  8. Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历
  9. HttpCookie
  10. 《Metasploit魔鬼训练营》第四章(下)
  11. ObjectiveC 深浅拷贝学习
  12. Struct2 基础介绍
  13. golang:常量
  14. [PHP] 算法-邻接矩阵图的广度和深度优先遍历的PHP实现
  15. angularjs 在 iframe 里面无法正确显示 src 指定的内容
  16. [转][osg]关于PagedLOD 加载卸载机制
  17. 编写第一个python selenium-webdriver程序(二)
  18. 【Python】keras神经网络识别mnist
  19. 【Android】隐藏底部虚拟按键
  20. ESET NOD32 Antivirus – 免费 3个月/ 3PC

热门文章

  1. atitit.提升研发效率的利器---重型框架与类库的差别与设计原则
  2. js判断访问者是否来自移动端代码
  3. sass笔记-1|Sass是如何帮你又快又好地搞定CSS的
  4. NYOJ-745蚂蚁的难题(二)
  5. codevs 1027 姓名与ID
  6. JavaScript 浮点数运算 精度问题
  7. GridView下DropDownList 的选择方法onselectedindexchanged 实现方法
  8. (转)JQuery中$.ajax()方法参数详解
  9. uva 482 - Permutation Arrays
  10. Nginx并发访问优化