HDU 4715 Difference Between Primes (打表)
Difference Between Primes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 860 Accepted Submission(s): 278
6
10
20
13 3
23 3
思路 : 打表
总结: 不要忘了有负数的情况,
使用 Scanner sc = new Scanner(new BufferedInputStream(System.in)); 和
System.out.println(); 程序执行时间如下图
使用: BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); 和
PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out),true); 程序如下图
import java.io.*;
import java.util.*;
public class Main {
int max=(int)Math.pow(10, 6)+10;
boolean a[]=new boolean[max];
public static void main(String[] args) throws IOException{
new Main().work();
}
void work() throws IOException{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out),true);
isPrime();
int n=Integer.parseInt(bu.readLine());
while(n--!=0){
int x=Integer.parseInt(bu.readLine());
int m=x>0?x:Math.abs(x);
boolean boo=true;
int i=2;
for(;i<max;i++){
if(a[i+m]&&a[i]){
boo=false;
break;
}
}
if(!boo){
if(x>0)
pw.println((i+m)+" "+i);
else
pw.println(i+" "+(i+m));
}
else
pw.println("FAIL");
}
}
//素数表
void isPrime(){
Arrays.fill(a,true);
for(int i=2;i<max;i++){
if(a[i]){
for(int j=2*i;j<max;j+=i){
a[j]=false;
}
}
}
}
}
HDU 4715 Difference Between Primes (打表)的更多相关文章
- 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 (打表 枚举)
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- hdu 4715 Difference Between Primes(素数筛选+树状数组哈希剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=4715 [code]: #include <iostream> #include <cstdio ...
- hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题
题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hdoj 4715 Difference Between Primes 素数筛选+二分查找
#include <string.h> #include <stdio.h> const int maxn = 1000006; bool vis[1000006]; int ...
- HDU 4715:Difference Between Primes
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- HDU 4548 美素数(打表)
HDU 4548 美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目 ...
- HDU 5487 Difference of Languages(BFS)
HDU 5487 Difference of Languages 这题从昨天下午2点开始做,到现在才AC了.感觉就是好多题都能想出来,就是写完后debug很长时间,才能AC,是不熟练的原因吗?但愿孰能 ...
随机推荐
- DenyHosts 安装及配置详解
DenyHosts是Python语言写的一个程序,它会分析sshd的日志文件(/var/log/secure),当发现重 复的攻击时就会记录IP到/etc/hosts.deny文件,从而达到自动屏IP ...
- Gentoo Linux 学习笔记1
Gentoo Linux是一个基于portage进行包管理的Linux发行版,最早版本始于2002年.其官方官网为http://www.gentoo.org 目前,Gentoo Linux已 ...
- Oracle 导出HTML
http://www.linuxidc.com/Linux/2010-10/29133.htm Oracle 执行计划: http://czmmiao.iteye.com/blog/1471756 h ...
- Learn X in Y minutes(python一页纸代码)
一篇非常好的文章,解释了python基本语法的方方面面: # Single line comments start with a hash. """ Multiline ...
- fuel iso光盘刻录机usb Driver 烧录
ISO image to a DVD or burn the IMG file to a USB drive For a bare-metal installation ipmitool, HP iL ...
- leftpad填充函数;
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【Apache ZooKeeper】为ZNode设置watcher
众所周知,ZooKeeper中的ZNode是树形结构,现在我需要给/app1结点设置watcher,监听/app1下增减.删除和修改的结点,并将相应的事件使用log4j记录到日志文件中.ZNode的变 ...
- IOS 8弃用api
IOS 8弃用api 下面api是弃用: 的 UIApplication 方法和属性注冊通知. 使用新的API. 的 uiviewcontroller 面向接口的方法和属性. 中描写叙述的特征和大小类 ...
- JavaScript的一些小用法
1.if问题: var a="this test"; if (a == "this test") //这样写的时候执行不下去了,不知为什么. 修改: var a ...
- bootstrap的导航改造
在使用bootstrap制作后台时用到了响应式导航条,其中dropdown组件更是用的比较多,用的多需要点击的就多,dropdown默认鼠标左键单击才展开,如果使用鼠标放上去(hover)就展开则会省 ...