链接:

https://vjudge.net/problem/LightOJ-1259

题意:

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.

思路:

素数表,然后暴力。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map> using namespace std;
typedef long long LL;
const int INF = 1e9; const int MAXN = 1e7+10;
const int MOD = 1e9+7; bool IsPrime[MAXN];
int Prime[1000010];
int n, tot; void Init()
{
memset(IsPrime, 0, sizeof(IsPrime));
IsPrime[1] = 1;
tot = 0;
for (int i = 2;i < MAXN;i++)
{
if (IsPrime[i] == 0)
Prime[++tot] = i;
for (int j = 1;j <= tot && i*Prime[j] < MAXN;j++)
{
IsPrime[i*Prime[j]] = 1;
if (i%Prime[j] == 0)
break;
}
}
} int main()
{
Init();
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%d", &n);
int sum = 0;
for (int i = 1;i <= tot && Prime[i] <= n/2;i++)
{
if (IsPrime[n-Prime[i]] == 0)
sum++;
}
printf(" %d\n", sum);
} return 0;
}

LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)的更多相关文章

  1. LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)

    http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...

  2. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  3. LightOJ 1259 Goldbach`s Conjecture 水题

    不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...

  4. LightOJ1259 Goldbach`s Conjecture —— 素数表

    题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture    PDF (English) Statistic ...

  5. Light oj-1259 - Goldbach`s Conjecture

                                                                                    1259 - Goldbach`s Co ...

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

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

  7. Goldbach's Conjecture

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

  8. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

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

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

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

随机推荐

  1. Java基础笔试练习(十二)

    1.(C#.JAVA)扩展方法能访问被扩展对象的public成员 A.能 B.不能 答案: A 解析: 翻译一下,子类方法是否能够访问父类中的public成员. 2.如果子类要调用父类的构造函数,则通 ...

  2. CF991E Bus Number

    题意翻译 给你一个数字序列A(长度不超过18位),问有多少个序列B满足①A中所有数字都一定要在B中出现过:②B中所有数字也一定要在A中出现过:③序列B不能以0开头 输入 #1 97 输出 #1 2 解 ...

  3. 经典例题(Python)

    经典例题 if嵌套 1.用户输入账号2.用户输入密码3.判断用户的账号是不是alex4.如果账号是alex在继续判断密码是不是alexdsb5.账号和密码都正确提示用户alex就是一个dsb6.如果账 ...

  4. Spring Cloud常用组件及各组件版本对应关系图

    Spring Cloud常用组件: 架构图: 版本对应关系:

  5. quartz2.3.0(二)触发器Trigger花式Scheduler调度job

    任务类 package org.quartz.examples.example2; import java.util.Date; import org.slf4j.Logger; import org ...

  6. Qt5 源代码自动跳转

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/nixiaoxianggong/articl ...

  7. 消息认证码 - MAC (Message Authentication Code)

    消息认证包括两个目标 1消息完整性认证: 确保张三发给我的消息是完整的,在传输过程中没有被第三方篡改 2消息的来源认证: 确保这个数据是张三发给我的,而不是李四发给我的 第一个目标通常使用散列函数来达 ...

  8. 查看font字体文件

    url: http://bluejamesbond.github.io/CharacterMap/ 打开网址后,如下图操作

  9. trie树(前缀树)详解——PHP代码实现

    trie树常用于搜索提示.如当输入一个网址,可以自动搜索出可能的选择.当没有完全匹配的搜索结果,可以返回前缀最相似的可能. 一.Tire树的基本性质 根节点不包含字符,除根节点外每一个节点都只包含一个 ...

  10. Programming Principles and Practice Using C++ Notes1

    序 0.4 创造性和问题求解 首要目标是帮助你学会用代码表达你的思想2,而不是叫你如何获得这些思想.沿着这样一个思路,给出很多实列,展示如何求解问题. 我们认为程序设计本事是问题求解的一种描述形式: ...