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 ;
}

HDU_1239——再次调用外星智慧的更多相关文章

  1. bzoj 1923 [Sdoi2010]外星千足虫(高斯消元+bitset)

    1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 634  Solved: 397[Submit][Status ...

  2. 【阿里聚安全·安全周刊】科学家警告外星恶意代码|新方法任意解锁iPhone

    本周的七个关键词: 外星恶意代码 丨 任意解锁iPhone 丨  安卓9.0 丨 黑客攻击医疗设备 丨 仙女座僵尸网络 丨  苹果联合创始人被骗比特币 丨JavaScript -1-   [恶意代码] ...

  3. TP5调用小程序微信支付,回调,在待支付中再次调用微信支付

    1,必须要有 $mch_id $key $appid这三个值,是需要去申请的,我是直接用公司的2,购买商品订单号用户openid统一下单名称商品价格(必须以分为单位,调起微信支付)服务器的ip地址(没 ...

  4. 【BZOJ-1923】外星千足虫 高斯消元 + xor方程组

    1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 766  Solved: 485[Submit][Status ...

  5. 【BZOJ-2251】外星联络 后缀数组 + 暴力

    2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 670  Solved: 392[Submit][ ...

  6. bzoj 2251: [2010Beijing Wc]外星联络 后缀数组

    2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 424  Solved: 232[Submit][ ...

  7. python中的嵌套类(内部类调用外部类中的方法函数)

    在为书中版本是3.X的,但2.X不太支持直接调用. 所以,在PYTHON2.X中,要在内部类中调用外部类的方法,就必须得实例化外部类,然后,传入实例进行调用. 花了我两个小时啊,资料没找到,自己一个一 ...

  8. BZOJ 1923: [Sdoi2010]外星千足虫 [高斯消元XOR]

    1923: [Sdoi2010]外星千足虫 对于 100%的数据,满足 N≤1,000,M≤2,000. 裸高斯消元解异或方程组 给定方程顺序要求用从上到下最少的方程,那么找主元时记录一下最远找到哪个 ...

  9. BZOJ_1923_[Sdoi2010]外星千足虫_高斯消元+bitset

    BZOJ_1923_[Sdoi2010]外星千足虫_高斯消元 Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结 ...

随机推荐

  1. 桌面环境与桌面搜索Desktop Search tools

    最近一段时间工作重心都将放在Linux下Desktop search(桌面搜索)框架的研发上.因此对desktop search进行了初步的调研.本文将从下面三个方面展开: Linux桌面环境(Des ...

  2. Android应用程序安装与Launcher启动机制

      以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luoshe ...

  3. 在linux后台执行脚本

    1. 使用&符号在后台执行命令 你可以在Linux命令或者脚本后面增加&符号,从而使命令或脚本在后台执行,例如:. $ ./my-shell-script.sh & 2. 使用 ...

  4. 1202.2——Xcode部分快捷键

    Ctrl+N(Next)  光标跳到下一行 Ctrl+P(Previous)   光标跳到上一行 Ctrl+B(Back) 光标向左边移动一个字符 Ctrl+F(Forward)   光标向右边移动一 ...

  5. JavaAppArguments.java程序的更改

       此程序模仿JvaAppArgyments.java编写,从命令行接受多个数字,求和之后输出结果.  设计思想:命令行参数都是字符串,可以考虑用 Integer.parseInt(args[]) ...

  6. C++程序设计教程学习(0)-引子

    回想一下从事C++相关开发工作已经有4年,主要从事基于MFC.Duilib等GUI框架开发进行windows应用程序开发,还涉及了一些开源的项目.但是真的谈起这门语言或多或少都会有些心虚,关于C++的 ...

  7. Java中 int和Integer的区别+包装类

    --今天用Integer 和Integer 比较 发现有问题,于是去查了查. 1.Java 中的数据类型分为基本数据类型和引用数据类型 int是基本数据类型,Integer是引用数据类型: Inget ...

  8. HTML5 canvas 中的线条样式

    线条样式属性 lineCap        设置或返回线条的结束端点样式 butt         默认.向线条的每个末端添加平直的边缘. round         向线条的每个末端添加圆形线帽. ...

  9. ios nslog 打印字典为中文

    #import <Foundation/Foundation.h> @implementation NSDictionary (Log) - (NSString *)description ...

  10. php获取汉字首字母

    php获取汉字首字母,可以用于按字母对数据进行检索排序等. 分享下网上找的代码.亲测有效. function getFirstCharter($str){ if(empty($str)){return ...