hdu 4715(打表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715
思路:先打个素数表,然后判断一下就可以了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; bool isprime[];
int num[]; int main()
{
int k=;
memset(isprime,true,sizeof(isprime));
isprime[]=isprime[]=false;
for(int i=;i<sqrt(*1.0);i++){
if(isprime[i]){
for(int j=i*i;j<;j+=i){
isprime[j]=false;
}
}
}
for(int i=;i<;i++){
if(isprime[i])num[k++]=i;
}
int _case,n;
scanf("%d",&_case);
while(_case--){
scanf("%d",&n);
if(n==){
puts("2 2");
}else if(n<){
n=-*n;
bool flag=false;
for(int i=;i<k;i++){
if(isprime[num[i]+n]){
flag=true;
printf("%d %d\n",num[i],num[i]+n);
break;
}
}
if(!flag)puts("FAIL");
}else {
bool flag=false;
for(int i=;i<k;i++){
if(isprime[num[i]+n]){
flag=true;
printf("%d %d\n",num[i]+n,num[i]);
break;
}
}
if(!flag)puts("FAIL");
}
}
return ;
}
hdu 4715(打表)的更多相关文章
- HDU 4715 Difference Between Primes (打表)
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4715 Difference Between Primes (打表 枚举)
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- 【Difference Between Primes HDU - 4715】【素数筛法打表+模拟】
这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include&l ...
- hdu 4715 Difference Between Primes
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...
- hdu 4715 Difference Between Primes(素数筛选+树状数组哈希剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=4715 [code]: #include <iostream> #include <cstdio ...
- hdu 4542 打表+含k个约数最小数
http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...
- HDU 1223 打表 + 大数
http://acm.hdu.edu.cn/showproblem.php?pid=1223 一般遇到这些题,我都是暴力输出前几项,找规律.未果. 然后输出n = 1时候,以A开始,有多少个答案, n ...
- hdu 3652 打表
思路:直接打表 #include<cstdio> #include<vector> #include<cmath> #include<iostream> ...
- hdu 5183 hash表
BC # 32 1002 题意:给出一个数组 a 和一个数 K ,问是否存在数对( i , j ),使 a i - a i + 1 +……+ (-1)j - i a j : 对于这道题,一开始就 ...
随机推荐
- 在 VirtualBox 虚拟机中安装 Arch Linux 系统指南
How to install Arch Linux on VirtualBox 在 VirtualBox 虚拟机中安装 Arch Linux 系统指南 本文导航 1.Arch Linux 软件仓库2. ...
- eclipse中查看某个方法(函数)被谁调用
用了好久一直不知道eclipse中怎样实现vs中查找全部引用的功能,今天最终发现了哈哈 选中要查找的方法名,右键->References->Workspace 能够定位到详细的调用位置,快 ...
- c#:无法将 NULL 转换成“System.DateTime”,因为它是一种值类型(转)
摘自:http://www.blogjava.net/parable-myth/archive/2010/09/30/333454.html 在C# 2.0里面的数据类型中,分为值类型和引用类型,引用 ...
- ML 与 DM 工具 Weka 的使用
1.关于Weka Weka 的全名是怀卡托智能分析环境(Waikato Environment for Knowledge Analysis),是一款免费的.非商业化(与之对应的是SPSS公司商业数据 ...
- Motion Detection Algorithms视频中运动检测算法源代码及演示代码
原文地址:http://www.codesoso.com/code/Motion_Detection.aspx 本文实现了在连续视频数据流中几种不同的运动检测算法,他们都是基于当前帧图像和前一帧图像的 ...
- EMQ ---问题集
1)emqttd 使用 SSL遇到的问题:服务器直接布了一份emqttd ,然后什么都没管,端口默认的ws 8083,wss8084,mqtt 1883,mqtt(ssl) 8883. 结果跑起来之后 ...
- 剩下5种算法代码分析与使用示例(remove 、rotate 、sort、lower_bound、accumulate)
一.移除性算法 (remove) C++ Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...
- C数组逆序
一.标准交换模式 /**** *标准交换模式 *实现数组的逆序,原理就是数组的首尾元素进行交换 ***/ #define N 5; int main(){ int array[N] = {15,20, ...
- iOS第三方开源库的吐槽和备忘
转自:http://blog.ibireme.com/2013/09/23/ios-third-party-libs/#more-41361 由 ibireme 发表于 2013/09/23 做iOS ...
- JAVA多线程之synchronized和volatile实例讲解
在多线程中,提到线程安全.线程同步,我们经常会想到两个关键字:volatile和synchronized,那么这两者有什么区别呢? 1. volatile修饰的变量具有可见性 volatile是变量修 ...