Levy Conjecture
来源:互联网 发布:常熟淘宝美工招聘 编辑:程序博客网 时间:2024/06/02 04:26
Levy Conjecture
Problem code: LEVY
Problem Statement
Levy's conjecture, named after Hyman Levy, states that all odd integers greater than5 can be represented as the sum of an odd prime number and an even semiprime. To put it algebraically,2n + 1 = p + 2q always has a solution in primes p andq (not necessary to be distinct) forn > 2. (Source: Wikipedia)
In this problem, given a positive integer N (not necessary to be odd integer greater than5). Your task is to calculate how many distinct ordered pairs(p, q) such that N = p + 2q, where p andq are primes.
Input
The first line of input contains an integer T, denoting the number of test cases. ThenT test cases follow.
Each test case consists of exactly one line containing an integer N.
Constraints
- 1 ≤ T ≤ 100000 (105)
- 1 ≤ N ≤ 10000 (104)
Output
For each test case, output the number of ordered pairs (p, q) of primes such thatN = p + 2q.
Example
Input:32711Output:012
Explanation
Case #1: There are no ordered pairs (p, q) such thatp + 2q = 2.
Case #2: There is only one ordered pair (p, q) = (3, 2) such thatp + 2q = 7.
Case #3: There are two ordered pairs (p, q) = (7, 2), (5, 3) such thatp + 2q = 11.
#include<iostream>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 100000
int sieve[N + 1];
int prime[100002],k=0;
//质数表
void Cprime(){
int i;
for( i = 2; i <= N; i++) sieve[i] = 1;
for(i = 2; i <= N / 2; i++) sieve[i * 2] = 0;
int p = 2;
while(p * p <= N)
{
p = p + 1;
while(sieve[p] == 0)
p++;
int t = p * p;
int s = 2 * p;
while(t <= N)
{
sieve[t] = 0;
t = t + s;
}
}
for(i=2;i<=N;i++)
if(sieve[i]!=0)
prime[k++]=i;
return ;
}
int main()
{
int t;
cin>>t;
Cprime();
sieve[1]=sieve[0]=0;
while(t--)
{
int n,i,count=0;
cin>>n;
for(i=0;i<k;i++)
{
if((2*prime[i])<n&&sieve[n-2*prime[i]]!=0)
{
// cout<<prime[i]<<" "<<n-2*prime[i]<<endl;
count++;
}
else
if((2*prime[i])>=n)
break;
}
cout<<count<<endl;
}
return 0;
}
- Levy Conjecture
- Steven Levy:“Google 特立独行”
- Triangle Conjecture
- 主数据管理的Jill Dyche, Evan Levy六层次模型
- Goldbach's Conjecture
- poj2262 Goldbach's Conjecture
- XTU 1142 Collatz Conjecture
- Goldbach's Conjecture
- Goldbach's Conjecture
- HOJ1459 Goldbach's Conjecture
- POJ2262 Goldbach's Conjecture
- 2262 Goldbach's Conjecture
- Goldbach's Conjecture
- POJ2262:Goldbach's Conjecture
- HDU1397:Goldbach's Conjecture
- Goldbach's Conjecture
- Goldbach's Conjecture
- poj_2262Goldbach's Conjecture
- c语言不同源文件间函数的调用
- C51,faster,faster,we need faster
- MySql1045错误:Access denied for user 'root'@'localhost' (using password:YES)
- 哈哈,你猜
- 最近研究libjingle的经验总结
- Levy Conjecture
- 五年专业编程的14个经验
- POJ 1681- Painter's Problem
- Java 的 SQL 事务处理
- 毕设小结(二)Android进程间通信之LocalSocket
- MFC中CreatThread()创建线程使用详解
- 将其他格式的文档 转换成 pdf格式
- 【Java】开发书籍
- c++涉及继承和虚继承时的内存布局