题目链接: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(打表)的更多相关文章

  1. HDU 4715 Difference Between Primes (打表)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  2. hdu 4715 Difference Between Primes (打表 枚举)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  3. 【Difference Between Primes HDU - 4715】【素数筛法打表+模拟】

    这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include&l ...

  4. hdu 4715 Difference Between Primes

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...

  5. hdu 4715 Difference Between Primes(素数筛选+树状数组哈希剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 [code]: #include <iostream> #include <cstdio ...

  6. hdu 4542 打表+含k个约数最小数

    http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...

  7. HDU 1223 打表 + 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=1223 一般遇到这些题,我都是暴力输出前几项,找规律.未果. 然后输出n = 1时候,以A开始,有多少个答案, n ...

  8. hdu 3652 打表

    思路:直接打表 #include<cstdio> #include<vector> #include<cmath> #include<iostream> ...

  9. hdu 5183 hash表

    BC # 32 1002 题意:给出一个数组 a 和一个数 K ,问是否存在数对( i , j ),使 a i   - a i + 1 +……+ (-1)j - i  a j : 对于这道题,一开始就 ...

随机推荐

  1. Android开发之语音识别

    2013-07-03 语音识别 2008年Google语音搜索在iphone平台上线,Android 1.5 将语音识别应用到搜索功能上. 手动输入是目前主要与手机互动的方式,语音搜索宗旨是最大限度地 ...

  2. Android4.0源码Launcher启动流程分析【android源码Launcher系列一】

    最近研究ICS4.0的Launcher,发现4.0和2.3有稍微点区别,但是区别不是特别大,所以我就先整理一下Launcher启动的大致流程. Launcher其实是贯彻于手机的整个系统的,时时刻刻都 ...

  3. Linux下 sleep函数的注意事项

    1. 休眠sleep(unsigned int)为线程内操作  所以如果不同线程,信号量SIGALRM是不能中断sleep():  编写程序进行测试 //timercreate_demo.cpp #i ...

  4. ajax异步请求,session失效处理

    后台拦截器代码: // 判断是否是AJAX请求 if (isAjaxRequest(request)) { log.info("AjaxRequest请求"); ActionCon ...

  5. Linux关机和重启命令总结

    一.shutdown 命令 作用:关闭或重启系统 使用权限:超级管理员使用 常用选项 1. -r 关机后立即重启 2. -h关机后不重启 3. -f快速关机,重启时跳过fsck(file system ...

  6. vue组件调用(全局调用和局部调用)

    当用vue-cli创建一个项目后, 创建项目的方法: https://www.cnblogs.com/fps2tao/p/9376847.html 编写了组件怎么,在其他组件中调用了? 组件listB ...

  7. unity, destroy gameObject & destroy all children

    一,destroy gameObject 删除名为xxx的gameObject 错误方法1: Destroy(xxx); 以上方法之所以错误,是因为Destroy在下一帧才生效,而在本帧之内xxx还存 ...

  8. informix遇到错误 25571:Cannot create an user thread

    今天发现informix数据库不能用dbaccess访问,报错:   25571: Cannot create an user thread. On NT check username, and IX ...

  9. 基于Java Netty框架构建高性能的Jt808协议的GPS服务器(转)

    原文地址:http://www.jt808.com/?p=971 使用Java语言开发一个高质量和高性能的jt808 协议的GPS通信服务器,并不是一件简单容易的事情,开发出来一段程序和能够承受数十万 ...

  10. JavaScript判断浏览器类型及版本(新增IE11)

    $(function () { var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/rv:( ...