Calling Extraterrestrial Intelligence Again
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: ← →
Problem Description
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 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
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相关推荐
- 413:Calling Extraterrestrial Intelligence Again(翻译 )
来源:http://noi.openjudge.cn/ch0207/413/ Calling Extraterrestrial Intelligence Again 总时间限制: 1000ms 内存限 ...
- HDU 1239 Calling Extraterrestrial Intelligence Again
题目 http://acm.hdu.edu.cn/showproblem.php?pid=1239 Problem Description A message from humans to extra ...
- 08:Calling Extraterrestrial Intelligence AgainMOOC程序设计算法基础期末第八题
问题表述: A message from humans to extraterrestrial intelligence was sent through the Arecibo radio tele ...
- 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)
http://poj.org/problem?id=1411 POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...
- 【HDOJ】1239 Calling Extraterrestrial Intelligence Again
这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来. 1 #include <stdio.h> 2 #include <string.h> 3 #include ...
- 【筛法求素数】HDU-1239 Calling Extraterrestrial Intelligence Again
注解 1.首先用筛法求100000以内的素数,并找到其个数. 2.在所有找到的素数中,遍历找一个素数对,满足: (1)二者相乘小于等于m: (2)二者相乘是所有满足条件的素数对中的最大的: (3)二者 ...
- POJ 1411 Calling Extraterrestrial Intelligence Again G++ 易超时
#include <iostream> #include <cstdio> using namespace std; //英语 抄博友程序 博友程序更快 易超时 int pri ...
- 大学英语(第六册)复习(原文及全文翻译)——Unit 3 - The Quest For Extraterrestrial Intelligence(搜寻外星人)
Unit 3 - The Quest For Extraterrestrial Intelligence Are we humans alone in the universe? Or is ther ...
- 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_ ...
最新文章
- 优秀Java程序员应该知道的20个实用开源库
- 招募 | 《大数据实践课》课程实践企业合作项目
- cocos2d JS 自定义事件分发器(接收与传递数据) eventManager
- mysql5.5.28安装详最后一个步骤时为啥一直转_mysql5.7.28下载、安装、登陆步骤详解...
- Discuz常见小问题-如何快速清除帖子
- leetcode -day19 Convert Sorted List to Binary Search Tree
- Hibernate 简介(百度)
- 随机生成六位不重复数值
- git config设置用户名_git从安装到多账户操作一套搞定(二)多账户使用
- linux 脚本返回值
- 怎么自动选中select中所有option
- 拓端tecdat|R语言回归和主成分PCA 回归交叉验证分析预测城市犯罪率
- 基于ZStack构建深度学习云平台
- c++ string 删除第一个字符_字符串操作的全面总结
- Hadoop学习之本地运行hadoop
- Tensorflow函数测试之tf.contrib.layers.embed_sequence
- 服务器内置usb能否修改为外置,台式机内置的DVD刻录机可以改成外置的USB接口吗?...
- python学习之 利用蒙特卡洛方法计算PI值
- get-element-by-id转换为getElementById
- 简账(开源记账软件)-前端环境简介及部署
热门文章
- ENVI-landsat7/8全色与多光谱波段图像融合前,全色波段辐射定标报错指南
- python 并行执行_python 串行执行和并行执行实例
- 计算机系统要素高清pdf,计算机系统要素:从零开始构建现代计算机[PDF][43.21MB]...
- Oracle 聚合实现小计、合计 (GROUP BY ROLLUP)
- 【理论-Cisco】策略路由PBR
- 最全MySQL面试题和答案
- Maven项目Dependencies常见报错及解决方案
- 冯绍峰,如果你爱她,记得不要把名字倒过来讲!
- 手把手教你做第一个RPA机器人流程
- 谨以此文纪念我的2020——不负热爱,砥砺前行