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, ...
    1. #include<iostream>
    2. #include<cstdio>
    3. #include<cmath>
    4. #include<cstring>
    5. #include<sstream>
    6. #include<algorithm>
    7. #include<queue>
    8. #include<deque>
    9. #include<iomanip>
    10. #include<vector>
    11. #include<cmath>
    12. #include<map>
    13. #include<stack>
    14. #include<set>
    15. #include<fstream>
    16. #include<memory>
    17. #include<list>
    18. #include<string>
    19. using namespace std;
    20. typedef long long LL;
    21. typedef unsigned long long ULL;
    22. #define MAXN 10000001
    23. #define L 31
    24. #define INF 1000000009
    25. #define eps 0.00000001
    26. /*
    27. 打表 把所有素数存到一个vector中
    28. 然后用一个map保存所有和出现的次数
    29. 然后直接找就可以
    30. */
    31. bool notprime[MAXN];
    32. vector<int> prime;
    33.  
    34. void Init()
    35. {
    36. memset(notprime, false, sizeof(notprime));
    37. notprime[] = true;
    38. for (int i = ; i < MAXN; i++)
    39. {
    40. if (!notprime[i])
    41. {
    42. prime.push_back(i);
    43. for (int j = i + i; j < MAXN; j += i)
    44. notprime[j] = true;
    45. }
    46. }
    47. }
    48. int main()
    49. {
    50. Init();
    51. int T,n;
    52. cin >> T;
    53. for(int cas=;cas<=T;cas++)
    54. {
    55. cin >> n;
    56. vector<int>::iterator p = lower_bound(prime.begin(), prime.end(), n/);
    57. //cout << *p << endl;
    58. int cnt = ;
    59. for (vector<int>::iterator it = prime.begin(); it <= p && *it<=n/; it++)
    60. {
    61. if (!notprime[n - *it])
    62. {
    63. //cout << *it << ' ' << n - *it << endl;
    64. cnt++;
    65. }
    66. }
    67. printf("Case %d: %d\n", cas, cnt);
    68. }
    69. return ;
    70. }

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. codevs3342绿色通道(单调队列优化dp)

    3342 绿色通道  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold   题目描述 Description <思远高考绿色通道>(Green Pass ...

  2. AirtestIDE详解(跨平台的UI自动化编辑器)

    Airtest 是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具. AirtestIDE 是一个跨平台.多端(Windows.web.android.ios.游戏)的UI自动化测 ...

  3. Django基于JWT实现微信小程序的登录和鉴权

    什么是JWT? JWT,全称Json Web Token,用于作为JSON对象在各方之间安全地传输信息.该信息可以被验证和信任,因为它是数字签名的. 与Session的区别 一.Session是在服务 ...

  4. Java中的自定义注解

    ## 元注解 要声明一个注解, 我们需要元注解, 元注解是指注解的注解,包括@Retention, @Target, @Document, @Inherited. @Retention 注解的保留位置 ...

  5. 321 Create Maximum Number 拼接最大数

    已知长度分别为 m 和 n 的两个数组,其元素由 0-9 构成,直观地表示两个自然数各位上的数字.现在从这两个数组中选出 k (k <= m + n) 个数字拼接成一个新的数,要求从同一个数组中 ...

  6. [转]Oracle Client 11g安裝經驗

    本文转自:http://www.dotblogs.com.tw/shadow/archive/2011/11/08/54759.aspx 開發環境:本機(Win XP)的ASP.net 4 WebSi ...

  7. iOS动画——DynamicAnimate

    力学动画 以dynamicAnimate为首的力学动画是苹果在iOS7加入的API,里面包含了很多力学行为,这套API是基于Box2d实现的.其中包含了重力.碰撞.推.甩.和自定义行为. 涉及到的类如 ...

  8. UVM基础之----uvm_object

    uvm_void The uvm_void class is the base class for all UVM classes. uvm_object: The uvm_object class ...

  9. (三)Python 学习第三天--GUI桌面项目

    (代码参考了别人的代码,只做学习用途!!!最近因为写论文,好久没有记录,好内疚...今天学习了一个小案例,做一下) 主要使用模块:tkinter 代码如下: from tkinter import * ...

  10. Nagios事件机制实践

    Nagios事件机制实践  blog地址:http://www.cnblogs.com/caoguo 一.事件触发执行脚本 [root@Nagios ~]# cd /usr/local/nagios/ ...