HDU 1239 暴力
来源:互联网 发布:js 判断是否是整数 编辑:程序博客网 时间:2024/06/01 09:54
Calling Extraterrestrial Intelligence Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5092 Accepted Submission(s): 2686
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.
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.
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.
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 299999 999 9991680 5 161970 1 12002 4 110 0 0
Sample Output
2 2313 31323 7343 4337 53#include<cstdio>#include<cmath>#include<iostream>bool prime[10001]={0}; void IsPrime(){ prime[0]=prime[1]=0;prime[2]=1; for(int i=3;i<=10000;i++) prime[i]=i%2==0?0:1; int t=(int)sqrt(10000*1.0); for(int i=3;i<=t;i++) if(prime[i]) for(int j=i*i;j<10000;j+=2*i)//优化 prime[j]=0; } int main(){IsPrime();int pri[10010];int num = 0;for(int i = 0; i < 10000; i++){if(prime[i])pri[num++] = i;}int m, a, b;while(scanf("%d%d%d", &m, &a, &b)!=EOF && m && a && b){int a1=0,b1=0;for(int i=0;i<num;i++) for(int j=i;j<num;j++) { if(pri[i]*pri[j]>m||1.0*a/b>1.0*pri[i]/pri[j]) break; if(pri[i]*pri[j]>pri[a1]*pri[b1]) { a1=i; b1=j; } }printf("%d %d\n",pri[a1], pri[b1]);}return 0;}
0 0
- HDU 1239 暴力
- 【字符串暴力】hdu 2847
- HDU **** 暴力模拟
- HDU-1128 暴力搜索
- hdu 2438 暴力吧
- HDU 4175 暴力求解
- hdu 3332 暴力枚举
- HDU 3823 暴力枚举
- hdu 4608 暴力大数
- hdu 1702 暴力
- hdu 4585 shaolin (暴力)
- HDU 4576 Robot (暴力)
- hdu 3711 暴力
- HDU 3697 暴力贪心
- hdu 4499 Cannon(暴力)
- hdu 1394 暴力
- hdu 3720 暴力枚举
- hdu 4995 暴力
- c# winfrom程序中 enter键关联button按钮
- poj 3259 Wormhole【bellman_ford】
- Android基础入门教程——1.1 背景相关与系统架构分析
- 欢迎使用CSDN-markdown编辑器
- Java substring使用方法
- HDU 1239 暴力
- css的background 属性
- ThinkPHP创建应用的一般开发流程及实例
- [leetcode#4]Longest Common Prefix
- 操作系统原理学习总结
- Android 中的 Service 全面总结
- Java类构造方法中不同类型语句存在限制
- Android基础入门教程——1.2 开发环境搭建
- xcode7之后的创建视图方法