hdu 4715(Difference Between Primes)
2013-09-08 18:53
302 查看
题目链接:点击打开链接
题目大意:give you an even , you should output the difference of 2 primes
题目分析:even though it says if you cannot find the 2 primes you may printf(" fail")
yet,if you think carefully you will find that there must exist such primes.--->
题目总结:明明清晰明了的代码,runtime error了= =
又是sb 的小错误,什么时候才能改掉啊……
if(flag=-1) x=0-x; 有点怪异吧~!!! 应该是if (flag ==-1) x=0-x;
说多了是泪==
题目大意:give you an even , you should output the difference of 2 primes
题目分析:even though it says if you cannot find the 2 primes you may printf(" fail")
yet,if you think carefully you will find that there must exist such primes.--->
题目总结:明明清晰明了的代码,runtime error了= =
又是sb 的小错误,什么时候才能改掉啊……
if(flag=-1) x=0-x; 有点怪异吧~!!! 应该是if (flag ==-1) x=0-x;
说多了是泪==
#pragma comment(linker, "/STACK:16777216")//为了不re还开了栈开关- - #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; bool is_prime[1000800];//用之前的算法得出1000004之内的数都可以满足猜想,并且最大的ans才是1000151,所以筛选质数自然就可以确定范围;了 void init() { for(int i=0; i<1000800; i++) is_prime[i]=true; for(int i=2; i*i < 1000800;i++) if(is_prime[i]) { for(int j=2*i; j<1000800; j+=i) is_prime[j]=false; } } void solve(int x,int flag) { if(flag==-1) x=0-x; int i=x+2; while(i<1000800) { if(is_prime[i]&&is_prime[i-x]) { if(flag==1) printf("%d %d\n",i,i-x); else printf("%d %d\n",i-x,i); break; } i++; } } int main() { int n,x; init(); scanf("%d",&n); while(n--) { scanf("%d",&x); if (x<0) solve(x,-1); else solve(x,1); } return 0; }
相关文章推荐
- hdu 4715 Difference Between Primes
- HDU 4715 Difference Between Primes (筛法求素数)
- HDU 4715 Difference Between Primes(数学啊)
- hdu 4715 Difference Between Primes acm
- hdu 4715 Difference Between Primes
- hdu 4715 Difference Between Primes (打表 枚举)
- HDU 4715:Difference Between Primes
- hdu 4715 Difference Between Primes
- hdu 4715 Difference Between Primes
- Hdu 4715 Difference Between Primes (2013网络赛 warm up) & LightOJ 1259 Goldbach`s Conjecture(素数和差)
- hdu 4715 Difference Between Primes
- HDU 4715 Difference Between Primes
- HDU 4715 Difference Between Primes
- HDU 4715 Difference Between Primes
- hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题
- HDU 4715 Difference Between Primes (打表)
- hdu 4715 Difference Between Primes【筛法快速求素数表+思维】
- hdu 4715 Difference Between Primes (二分查找)
- HDU 4715 Difference Between Primes && 2013 ACM/ICPC Asia Regional Online —— Warmup
- HDU 4715 Difference Between Primes 半个打表题。。