Calling Extraterrestrial Intelligence Again

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3993    Accepted Submission(s): 2097

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
 
Source
 
Recommend

Eddy

题意:

给你一个大于4的整数m和一个真分数a/b,求最佳素数对p、q,使得a/b<=p/q<=1且pq<=m。最佳即为满足条件的pair中pq最大的一对。

感想:

关于素数打表的各种方法还是要好好研究一下。。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#define N 100005
using namespace std; bool no_prim[N];
int m,a,b,p,q; void primetable()
{
int i,j;
for(i=3;i<317;i+=2)
{
if(no_prim[i]==false)
{
int tmp=i<<1;
for(j=i*i;j<N;j+=tmp)
no_prim[j]=true;
}
}
} int main()
{
int i,j;
primetable();
while(scanf("%d%d%d",&m,&a,&b)&&m&&a&&b)
{
p=q=0;
double limit=a*1.0/b;
for(i=2;i<=m;i++)
{
if(!no_prim[i]&&i%2!=0||i==2)
{
for(j=2;j<=i&&i*j<=m;j++)
{
if(!no_prim[j]&&j%2!=0||j==2)
{
if(j*1.0/i>=limit&&i*j>p*q) //i和j的顺序
{
p=j;
q=i;
}
} }
}
}
printf("%d %d\n",p,q);
}
return 0;
}

hdu 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)的更多相关文章

  1. 【HDOJ】1239 Calling Extraterrestrial Intelligence Again

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

  2. poj 1411 Calling Extraterrestrial Intelligence Again(超时)

    Calling Extraterrestrial Intelligence Again Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

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

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

  4. 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 ...

  5. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

  6. hdu 4082 Hou Yi's secret(暴力枚举)

    Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. HDU 5944 Fxx and string(暴力/枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  8. hdu 4968 Improving the GPA (水 暴力枚举)

    题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10, ...

  9. HDU 5660 jrMz and angles (暴力枚举)

    jrMz and angles 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/E Description jrMz has tw ...

随机推荐

  1. Android - 采用ApiDemos得知Android开展

    采用ApiDemos得知Android开展 本文地址: http://blog.csdn.net/caroline_wendy 位置: android-sdk/samples/android-20/l ...

  2. 安卓开发笔记——探索EventBus(转)

    1.关于EventBus: 组件通讯在Android开发中是不可避免的,随着业务需求的复杂化,代码中需要我们去处理的业务逻辑难度也不断增大.例如多个Fragment之间的数据传递,Service与Ac ...

  3. OpenWrt arp 命令发布

    arp命令是用来查看mac与ip在消息路由器缓存表.这是一个基本的介绍了一下我就不说了. 但今天我的同事通过arp.可是在shell脚本就回显示没有此命令,我当时也感到非常费解. 于是乎.做了例如以下 ...

  4. 关于JavaScript中的事件代理

    今天面试某家公司Web前端开发岗位,前面的问题回答的都还算凑活,并且又问了一下昨天面试时做的一道数组去重问题的解题思路(关于数组去重问题,可以观赏我前几天写的:http://www.cnblogs.c ...

  5. sql小总结2

    SQL NULL 值 如果表中的某个列是可选的,那么我们可以在不向该列添加值的情况下插入新记录或更新已有的记录.这意味着该字段将以 NULL 值保存. NULL 值的处理方式与其他值不同. NULL ...

  6. Nlog 配置总结

    Writes log messages to one or more files. Since NLog 4.3 the ${basedir} isn't needed anymore for rel ...

  7. C#并行和多线程编程

    5天玩转C#并行和多线程编程 —— 第二天 并行集合和PLinq   5天玩转C#并行和多线程编程系列文章目录 5天玩转C#并行和多线程编程 —— 第一天 认识Parallel 5天玩转C#并行和多线 ...

  8. Android4.4 Framework分析——startService创建过程

    我们经常使用context.startService()要启动service.下面就来分析这service启动过程,下图是service启动序列图: watermark/2/text/aHR0cDov ...

  9. Contoso 大学 - 使用 EF Code First 创建 MVC 应用,实例演练

    Contoso 大学 Web 示例应用演示了如何使用 EF 技术创建 ASP.NET MVC 应用.示例中的 Contoso 大学是虚构的.应用包括了类似学生注册.课程创建以及教师分配等功能. 这个系 ...

  10. DP 水的问题

    假设的自然数N的K随机二进制表示是不相邻的两个相邻的数字.那么我们说这个数字是K好一些. 乞讨L地点K十六进制数K的相当数量的数. 例如K = 4.L = 2什么时候.整个K好一些11.13.20.2 ...