HDU_1239——再次调用外星智慧
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.
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.
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.
99999 999 999
1680 5 16
1970 1 1
2002 4 11
0 0 0
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——再次调用外星智慧的更多相关文章
- bzoj 1923 [Sdoi2010]外星千足虫(高斯消元+bitset)
1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 634 Solved: 397[Submit][Status ...
- 【阿里聚安全·安全周刊】科学家警告外星恶意代码|新方法任意解锁iPhone
本周的七个关键词: 外星恶意代码 丨 任意解锁iPhone 丨 安卓9.0 丨 黑客攻击医疗设备 丨 仙女座僵尸网络 丨 苹果联合创始人被骗比特币 丨JavaScript -1- [恶意代码] ...
- TP5调用小程序微信支付,回调,在待支付中再次调用微信支付
1,必须要有 $mch_id $key $appid这三个值,是需要去申请的,我是直接用公司的2,购买商品订单号用户openid统一下单名称商品价格(必须以分为单位,调起微信支付)服务器的ip地址(没 ...
- 【BZOJ-1923】外星千足虫 高斯消元 + xor方程组
1923: [Sdoi2010]外星千足虫 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 766 Solved: 485[Submit][Status ...
- 【BZOJ-2251】外星联络 后缀数组 + 暴力
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 670 Solved: 392[Submit][ ...
- bzoj 2251: [2010Beijing Wc]外星联络 后缀数组
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 424 Solved: 232[Submit][ ...
- python中的嵌套类(内部类调用外部类中的方法函数)
在为书中版本是3.X的,但2.X不太支持直接调用. 所以,在PYTHON2.X中,要在内部类中调用外部类的方法,就必须得实例化外部类,然后,传入实例进行调用. 花了我两个小时啊,资料没找到,自己一个一 ...
- BZOJ 1923: [Sdoi2010]外星千足虫 [高斯消元XOR]
1923: [Sdoi2010]外星千足虫 对于 100%的数据,满足 N≤1,000,M≤2,000. 裸高斯消元解异或方程组 给定方程顺序要求用从上到下最少的方程,那么找主元时记录一下最远找到哪个 ...
- BZOJ_1923_[Sdoi2010]外星千足虫_高斯消元+bitset
BZOJ_1923_[Sdoi2010]外星千足虫_高斯消元 Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结 ...
随机推荐
- PowerDesigner 生成带凝视SQL 各个版本号通用10(12、15)
做数据库是设计时最苦恼的事就是用PowerDesigner工具设计完数据库运行SQL文件后没有凝视.那么怎么才干让PowerDesigner设计完有凝视呢,下边教你一个笨的方法,方法尽管笨,可是能实现 ...
- 自定义控件 TextView 歌词 Lrc
演示 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> < ...
- RecycleView 滑动到底部,加载更多
android.support.v7 包提供了一个新的组件:RecycleView,用以提供一个灵活的列表试图.显示大型数据集,它支持局部刷新.显示动画等功能,可以用来取代ListView与GridV ...
- VS2010发布网站的基本步骤
1.首先建一个空文件夹,用来存放发布的程序:例如:WebTest 2.然后打开IIS--->右击--->添加网站,如下图所示: 图 1-1 ...
- oracle单行函数之字符函数
Lower--转换为小写 upper--转换为大写 Initcap--首字母大写 concat--连接字符 substr--截取字符 length/length--获取字符串长度(字节长度) inst ...
- Qt5如何设置静态编译,解决生成的可执行文件打开出错问题
将https://yunpan.cn/cqGGURjmG2fEY 访问密码 8de5 中的压缩包Qt5-MSVC-Static-master.zip 解压到你的qt安装目录,一般就是C:\Qt下, ...
- [转]Windows中的句柄(handle)
1.句柄是什么? 在windows中,句柄是和对象一一对应的32位无符号整数值.对象可以映射到唯一的句柄,句柄也可以映射到唯一的对象.2.为什么我们需要句柄? 更准确地说,是windows需要 ...
- linux初识-01简介
什么是linux: Linux是一个自由的,免费的,源码开发的操作系统Linux的特点: 开放性.多用户,多任务,具有丰富的网络功能 可靠的系统安全 良好的可移植性 良好的用户界面(命令界面和图形界面 ...
- 了解JVM
---恢复内容开始--- Java对象在运行环境中,对于内存而言,存在三种状态:年轻代.年老代.永生代: 下图是JVM内存模型 1. 年轻代被分为3个部分:Enden区和两个Survivor区,垃圾回 ...
- jquery判断滚动条到底
$(document).scroll(function(){ var dHeight = $(document).height(); var wHeight = $(window).height(); ...