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. android Json解析详解

    JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语 言的支持),从而可以在不同平台间进行数 ...

  2. C# 网络编程之网页简单下载实现

    这是根据<C#网络编程实例教程>中学到的知识实现的一个C#网页简单下载器,其中涉及到的知识主要是HTTP协议编程中相关类:HttpWebRequest类.HttpWebResponse类. ...

  3. Java基础知识强化29:String类之String类构造方法

    1. 常用String构造方法使用: package cn.itcast_01; /* * 字符串:就是由多个字符组成的一串数据.也可以看成是一个字符数组. * 通过查看API,我们可以知道 * A: ...

  4. Sending Signals to Processes with kill, killall, and pkill

    The Linux kernel allows many signals to be sent to processes. Use man 7 signals for a complete overv ...

  5. linux 网络状态工具ss命令

    ss命令用于显示socket状态. 他可以显示PACKET sockets, TCP sockets, UDP sockets, DCCP sockets, RAW sockets, Unix dom ...

  6. Hibernate 关联查询 相关错误

    错误提示: could not resolve property: 确定有相关属性时,记得使用 criteria.createAlias @ManyToOne 若可能为null 要加上 @NotFou ...

  7. ESXi控制台TSM:弥补vSphere Client不足

    当vSphere Client不能完成某些任务时,主机的ESXi控制台及其技术支持模式(TSM)可能能派上用场. ESXi控制台允许管理员执行不能通过vSphere Client进行配置的管理任务,比 ...

  8. ORACLE调度之基于时间的调度(一)【weber出品】

    一.调度的概述 这里我看到一篇对调度的概述觉得描述的比我好,但仅限于概述部分,其他部分我觉得我讲的比他好,于是发生以下事情: ************************华丽的转载******** ...

  9. php pdo_mysql使用方法

    <?php $dsn='mysql:host=127.0.0.1;port=3306;dbname=bisai'; $username='root'; $password=''; $driver ...

  10. 武汉科技大学ACM:1010: 零起点学算法89——母牛的故事

    Problem Description 有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年的时候,共有多少头母牛? Input 输入数据由多个测 ...