Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:

Every even integer, greater than 2, can be expressed as the sum of two primes [1].

Now your task is to check whether this conjecture holds for integers up to 107.

Input

Input starts with an integer T (≤ 300), denoting the number of test cases.

Each case starts with a line containing an integer n (4 ≤ n ≤ 107, n is even).

Output

For each case, print the case number and the number of ways you can express n as sum of two primes. To be more specific, we want to find the number of (a, b) where

1)      Both a and b are prime

2)      a + b = n

3)      a ≤ b

Sample Input

2

6

4

Sample Output

Case 1: 1

Case 2: 1

Hint

  1. An integer is said to be prime, if it is divisible by exactly two different integers. First few primes are 2, 3, 5, 7, 11, 13, ...
  2. #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<sstream>
    #include<algorithm>
    #include<queue>
    #include<deque>
    #include<iomanip>
    #include<vector>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<fstream>
    #include<memory>
    #include<list>
    #include<string>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    #define MAXN 10000001
    #define L 31
    #define INF 1000000009
    #define eps 0.00000001
    /*
    打表 把所有素数存到一个vector中
    然后用一个map保存所有和出现的次数
    然后直接找就可以
    */
    bool notprime[MAXN];
    vector<int> prime; void Init()
    {
    memset(notprime, false, sizeof(notprime));
    notprime[] = true;
    for (int i = ; i < MAXN; i++)
    {
    if (!notprime[i])
    {
    prime.push_back(i);
    for (int j = i + i; j < MAXN; j += i)
    notprime[j] = true;
    }
    }
    }
    int main()
    {
    Init();
    int T,n;
    cin >> T;
    for(int cas=;cas<=T;cas++)
    {
    cin >> n;
    vector<int>::iterator p = lower_bound(prime.begin(), prime.end(), n/);
    //cout << *p << endl;
    int cnt = ;
    for (vector<int>::iterator it = prime.begin(); it <= p && *it<=n/; it++)
    {
    if (!notprime[n - *it])
    {
    //cout << *it << ' ' << n - *it << endl;
    cnt++;
    }
    }
    printf("Case %d: %d\n", cas, cnt);
    }
    return ;
    }

F - Goldbach`s Conjecture kuangbin 基础数论的更多相关文章

  1. F - Goldbach`s Conjecture 对一个大于2的偶数n,找有多少种方法使两个素数的和为n;保证素数a<=b; a+b==n; a,b都为素数。

    /** 题目:F - Goldbach`s Conjecture 链接:https://vjudge.net/contest/154246#problem/F 题意:对一个大于2的偶数n,找有多少种方 ...

  2. 【LightOJ1259】Goldbach`s Conjecture(数论)

    [LightOJ1259]Goldbach`s Conjecture(数论) 题面 Vjudge T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方 ...

  3. [暑假集训--数论]poj2262 Goldbach's Conjecture

    In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...

  4. Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】

    Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...

  5. Goldbach’s Conjecture(信息学奥赛一本通 1622)

    [题目描述] 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 44 的偶数都可以拆成两个奇素数之和. 比如: 8=3+5 20=3+17=7+13 42=5+37=1 ...

  6. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  7. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

  8. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

  9. HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)

    Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...

随机推荐

  1. E20171005-ts

    collapse  n. 垮台; (身体的) 衰弱;              vt. 使倒塌; 使坍塌; 使瓦解;               vi. 崩溃; 倒塌; 折叠; (尤指工作劳累后) 坐 ...

  2. AOP注解不起作用的debug结果

    经过2天的调试,我发现AOP注解配置不起作用居然是表达式的错误导致的 在xml文件中配置的base-package有关,初步认为@PointCut只能使用base-package..*(..)这样的方 ...

  3. sublime text3配置插件

    之前一直习惯用记事本写代码,懒得用IDE,虽然知道用 IDE效率高一些,不过觉得还是用记事本纯手写代码,比较容易记忆.直到昨天写代码遇到了点问题,截图给师兄看,师兄就问我是不是用记事本写代码,为什么不 ...

  4. drupal 8——图片组(list)在前台的显示顺序在登录状态和非登录状态不同

    问题描述:该页面是通过view来输出的,然而,登录状态下其页面中的图片组输出顺序是乱序的,而非登录状态下则根据id值升序输出. 原因:在原view配置页面中,没有配置默认的排序字段 解决方案:在vie ...

  5. LAMP配置课程基础知识详解

    听了一天的课程,我本人对这个还是很感兴趣的. [root@localhost~]#     root 用户名 localhost 本地 ~  家目录 不同用户不同 #当前用户是管理员 $当前用户是普通 ...

  6. jQuery——表格添加数据

    1.遮罩层宽高100%,position,不占位 2.注册a标签的删除事件,用on()方法,以方法可以动态添加,之前js需要利用冒泡属性(父标签注册事件,子标签冒泡,target===li触发事件) ...

  7. html——特例

    1.a标签与a标签之间有3px距离 2.标准流中的文字不会被浮动的盒子遮挡 <div style="width:150px;height:150px;background-color: ...

  8. yum进程被占用

    使用yum安装软件的时候出现,/var/run/yum.pid 已被锁定,PID 为 6503 的另一个程序正在运行的问题 [root@localhost mysql]# yum install gc ...

  9. jenkins执行python脚本

    参考: https://blog.csdn.net/qq_39247153/article/details/81003244 https://blog.csdn.net/huashao0602/art ...

  10. PHP 数据库连接 (Mysql Mysqli PDO)

    1.PHP与Mysql扩展(本扩展自 PHP 5.5.0 起已废弃,并在将来会被移除),PHP原生的方式去连接数据库,是面向过程的 <?php $mysql_conf = array( 'hos ...