2013杭电warm_up1 1010 Difference Between Primes
来源:互联网 发布:王者传奇羽毛升级数据 编辑:程序博客网 时间:2024/06/07 00:29
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4715
首先打素数表,然后分三类 x=0,>0, <0就ac了
嗯嗯 验证了那句话 "这个问题我没解决,但是ac还是没问题的" 暴力能过的背后,如果数据不水,那么一定藏着数学原理保证实际运行效率不低。
代码:
#include<iostream>#include<cmath>#include<cstdio>using namespace std;#define N 10000000bool 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
- hdu4715 Difference Between Primes
- hdu4715 Difference Between Primes
- hdu 4715(Difference Between Primes)
- hdu 4715 Difference Between Primes
- hdu 4715Difference Between Primes
- hdu 4715 Difference Between Primes
- HDU 4715 Difference Between Primes
- HDU 4715 Difference Between Primes
- hdu 4715 Difference Between Primes
- Difference Between Primes----素数筛选
- 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(stl)
- HDU 4715 Difference Between Primes 半个打表题。。
- hdu(4715) Difference Between Primes
- POJ 2689 (素数的二次筛选)
- 网络基础知识总结
- HDU 2136
- C++拷贝构造函数详解
- java程序设计
- 2013杭电warm_up1 1010 Difference Between Primes
- 你究竟多想成功?(nba励志视频)
- C++拷贝构造函数(深拷贝、浅拷贝)
- uva 10361 Automatic Poetry
- Linux du命令
- 谈谈MSDN
- 网络值多少
- 内存_内存池
- Linux下安装Android的adb驱动-解决不能识别的问题