HDU 1239 Calling Extraterrestrial Intelligence Again(找素数)
来源:互联网 发布:直销软件制作xazxrj 编辑:程序博客网 时间:2024/05/22 00:10
http://acm.hdu.edu.cn/showproblem.php?pid=1239
题目很长,长就不说了,还是英文,这么长的英文也就算了,居然还是水题,我靠,坑嗲啊!!!
题意:输入 m a b 三个数
输出:p q
要求: p q 是素数,且 p*q <=m 是 <= ,,且 a/b <= p/q <= 1
4 < m <= 100000 and 1 <= a <= b <= 1000.
p,q的范围其实可在2—50000(why?)
然而,这是最小的范围吗?
考虑大于10000的某个质数,不妨设为Q,另一个质数为P,则:
1、如果P<10,P/Q<0.001
2、如果P>10,P*Q>100000
而考虑到a,b的取值范围(1<=a<=b<=1000)
可知min(a/b)=0.001
同时,要求: p*q<=m<=100000
所以无论如何质数都不能超过10000。(事实上,不会超过9091)
#include <stdio.h>#include <string.h>#include <queue>using namespace std;int l = 0;int prim[10005] = {1}, s[10005];void prime(){int i, j;memset(prim, 0, sizeof(prim));for (i = 2; i < 10005; i++){if (prim[i]){continue;}for (j = i + i; j < 10005; j += i){prim[j] = 1;}s[l++] = i;}}int main(){//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);prime();int m;double a , b;while (~scanf("%d %lf %lf", &m, &a, &b) && (m != 0 && a + b != 0)){int p = 0, q = 0;double x = a / b, y;int i, j;for (i = 0; i < l; i++){if (s[i] > m){break;}else{for (j = i; j<l ; j++){y = (double)s[i] / s[j];if (y >= x && s[i]*s[j] > q * p && s[i]*s[j] <= m){p = s[i];q = s[j];}}}}printf("%d %d\n", p, q);}}
0 0
- HDU 1239 Calling Extraterrestrial Intelligence Again(找素数)
- HDU 1239 Calling Extraterrestrial Intelligence Again 素数表
- HDU - 1239 - Calling Extraterrestrial Intelligence Again (素数相关~)
- hdu 1239 Calling Extraterrestrial Intelligence Again(素数,枚举)
- HDU 1239 Calling Extraterrestrial Intelligence Again (素数)
- 【HDU 1239】Calling Extraterrestrial Intelligence Again(素数+暴力)
- hdu 1239Calling Extraterrestrial Intelligence Again
- Hdu 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- HDU 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- HDU 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- HDU 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- 【HDU】 1239 Calling Extraterrestrial Intelligence Again
- Sphider 的应用和php源码分析
- WinForm程序中两份mdf文件问题的解决(转载 )
- hdu 4893 线段树
- 机器学习第二篇(stanford大学公开课学习笔记) —局部加权回归
- 立即调用的函数表达式
- HDU 1239 Calling Extraterrestrial Intelligence Again(找素数)
- UVA - 414 Machined Surfaces
- 『转』Spring Security的核心拦截器
- eclipse中为android工程第三方jar包关联源代码的方法
- Qt核心剖析: moc
- 杭电2546————DP之01背包
- 搭建Windows Red5流媒体服务器详解
- 基于ADNROID 检测网络是否可用的两种方式
- Android自动检测更新