HDUOJ-----Difference Between Primes
Difference Between Primes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 832 Accepted Submission(s): 267
#include<iostream>
#include<cstdio>
#define maxn 1000000
using namespace std;
int prime[];
bool bo[maxn+];
int prime_table()
{
int i,j,flag=;
memset(bo,,sizeof bo);
bo[]=bo[]=;
for(i=; i*i<=maxn;i++)
{
if(!bo[i])
{
for(j=i*i;j<=maxn;j+=i)
bo[j]=;
}
}
for(i=;i<=maxn;i++)
if(!bo[i]) prime[flag++]=i;
return flag;
}
bool isprime(int a)
{
for(int i=;prime[i]*prime[i]<=a;i++)
{
if(a%prime[i]==)
return ;
}
return ;
} int main()
{
int i,t,b,num;
num=prime_table();
scanf("%d",&t);
while(t--)
{
scanf("%d",&b);
if(b>=)
{
for(i=;i<num;i++)
{ if(isprime(b+prime[i]))
{
printf("%d %d\n",prime[i]+b,prime[i]);
break;
}
}
}
else
{
for(i=;i<num;i++)
{ if(isprime(prime[i]-b))
{
printf("%d %d\n",prime[i],prime[i]-b);
break;
}
}
}
}
return ;
}
HDUOJ-----Difference Between Primes的更多相关文章
- 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 ...
- 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 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 (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
Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than ...
- 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后是否还 ...
- hdoj 4715 Difference Between Primes 素数筛选+二分查找
#include <string.h> #include <stdio.h> const int maxn = 1000006; bool vis[1000006]; int ...
- 【Difference Between Primes HDU - 4715】【素数筛法打表+模拟】
这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include&l ...
随机推荐
- strstr实现
// strstr.c查找完全匹配的子字符串 #include<stdio.h> #include<string.h> char *my_strstr(const char * ...
- 使用supervisor过程的坑
1.安装:由于使用的是公司的虚拟机,所以使用pip install supervisor的过程遇到很多权限问题. 中间尝试使用sudo pip install supervisor的方式安装,但是使用 ...
- 【屌丝程序的口才逆袭演讲稿50篇】第十三篇:爱迪生欺骗了我们!【张振华.Jack】
演讲稿主题:<爱迪生欺骗了我们> --作者:张振华Jack.摘抄<马云为雅虎员工的演讲稿:爱迪生欺骗了我们> 非常多人都记得爱迪生说的 ...
- 在Java Web程序中使用Hibernate
在Java Web程序中使用Hibernate与普通Java程序一样.本文中将使用Servlet和JSP结合Hibernate实现数据库表的增删改查操作. Web程序中,hibernate.cfg.x ...
- python 中面向对象编程的几个概念
Python super() 函数 super() 函数是用于调用父类(超类)的一个方法. super 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果使用多继承,会 ...
- Steps to configure a FileShare Quorum Witness for Windows Failover Cluster
Step 1: Step 2: Step 3: Step 4: You must use the wizard to create the file share. Step 5: to make su ...
- Jquery 获取第一个子元素
<ul> <li>John</li> <li>Karl</li> <li>Brandon</li></u ...
- 你应该抓紧学习Python,它是开发Web应用最强大的语言
Python和少数几种编程语言,如MySQL.Perl.PHP和与LAMP打包的网络结构一起的Apache,已经成为Linux的一个基本组件.即 使从它诞生开始,Python就与其他动态编程语言如Ru ...
- Aliasing input/output properties
angular @input alias别名的使用. https://angular.io/guide/template-syntax#aliasing-io https://stackoverflo ...
- Asp.net 恢复页面内用户控件内的控件ClientID
众所周知在Asp.net中如果一个页面添加了一个用户控件(或母版页),那么用户控件内的控件的 ClientID号会被自动添加页面中用户控件的ClientID 即页面中的控件内的控件ClientID ...