hdu 4715 Difference Between Primes
2013-09-08 22:36
471 查看
Difference Between Primes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 496 Accepted Submission(s): 136
[align=left]Problem Description[/align]
All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the difference of two primes.
To validate this conjecture, you are asked to write a program.
[align=left]Input[/align]
The first line of input is a number nidentified the count of test cases(n<10^5). There is a even number xat the next nlines. The absolute value of xis not greater than 10^6.
[align=left]Output[/align]
For each number xtested, outputstwo primes aand bat one line separatedwith one space where a-b=x. If more than one group can meet it, output the minimum group. If no primes can satisfy it, output 'FAIL'.
[align=left]Sample Input[/align]
3 6 10 20
[align=left]Sample Output[/align]
11 5 13 3 23 3
[align=left]Source[/align]
2013 ACM/ICPC Asia Regional Online —— Warmup
思路:用筛法将素数打表,然后二分查找,学会low_bound()函数,挺好用的
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <cstdlib> #include <queue> #include <stack> #include <vector> #include <cmath> using namespace std; const int maxn=500000; bool isprime[maxn]; int prime[maxn],nprime; void pre_solve() { nprime=0; isprime[1]=0; for(int i=2;i<maxn;i++) isprime[i]=true; for(long long i=2;i<maxn;i++) { if(isprime[i]) { prime[++nprime]=i; for(long long j=i*i;j<maxn;j+=i) isprime[j]=false; } } } int main() { //freopen("in.txt","r",stdin); pre_solve(); /* for(int i=1;i<=1;i++) cout<<prime[i]<<" ";*/ int n; scanf("%d",&n); while(n--) { int x; bool isfind=false; scanf("%d",&x); for(int i=1;i<=nprime;i++) { int t=lower_bound(prime+1,prime+1+nprime,prime[i]+x)-prime; if(prime[t]==prime[i]+x) { printf("%d %d\n",prime[t],prime[i]); isfind=true; break; } } if(!isfind) printf("FALL\n"); } return 0; }
相关文章推荐
- 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(stl)
- 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(数学啊)
- 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