2013杭电warm_up1 1010 Difference Between Primes
2013-09-19 16:45
405 查看
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4715
首先打素数表,然后分三类 x=0,>0, <0就ac了
嗯嗯 验证了那句话 "这个问题我没解决,但是ac还是没问题的" 暴力能过的背后,如果数据不水,那么一定藏着数学原理保证实际运行效率不低。
代码:
首先打素数表,然后分三类 x=0,>0, <0就ac了
嗯嗯 验证了那句话 "这个问题我没解决,但是ac还是没问题的" 暴力能过的背后,如果数据不水,那么一定藏着数学原理保证实际运行效率不低。
代码:
#include<iostream> #include<cmath> #include<cstdio> using namespace std; #define N 10000000 bool p[N+1]; void pre() { int d=sqrt(N); for(int i=2;i<=d;i++) if(p[i]==0) for(int j=i*i;j<=N;j+=i) p[j]=1; p[0]=1; p[1]=1; } int main() { pre(); int n,x; cin>>n; for(int i=0;i<n;i++) { int start=2; bool fail=true; scanf("%d",&x); if(x==0) { fail=0; printf("%d %d\n",start+x,start); } else if(x>0) { for(start=2;start<=10000000-x;start++) { if(!p[start]&&!p[start+x]) { fail=false; printf("%d %d\n",start+x,start); break; } } } else if(x<0) { for(start=-x;start<10000000;start++) { if(!p[start]&&!p[start+x]) { fail=false; printf("%d %d\n",start+x,start); break; } } } if(fail) printf("FAIL\n"); } }
相关文章推荐
- 2013杭电warm_up1 1010 Difference Between Primes
- 2013杭电warm_up1 1010 Difference Between Primes
- HDU 4715 Difference Between Primes && 2013 ACM/ICPC Asia Regional Online —— Warmup
- Hdu 4715 Difference Between Primes (2013网络赛 warm up) & LightOJ 1259 Goldbach`s Conjecture(素数和差)
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
- 2013杭电warm up1 1002 Pet 求树结点的高度(bfs,dfs两种求法)
- 2013杭电warm up1 1002 Pet 求树结点的高度
- 2013杭电warm up1 1002 Pet 求树结点的高度(bfs,dfs两种求法)
- hdu 4705 Y/杭电2013年多校第十场1010 组合
- hdu 4715 Difference Between Primes【筛法快速求素数表+思维】
- hdoj 4715 Difference Between Primes 素数筛选+二分查找
- hdoj 4715 Difference Between Primes 素数筛选+二分查找
- HDUOJ-----Difference Between Primes
- HDU 4715 Difference Between Primes (打表)
- 杭电暑假集训 Team Contests - Warmup G题
- hdu4715 Difference Between Primes
- hdu 4715 Difference Between Primes(素数筛选+树状数组哈希剪枝)
- hdu 4715 Difference Between Primes
- Difference Between Primes
- 2013杭电 warm 2, hdu 4717 The Moving Points 三分