链接:

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. python3遇到的问题

    a bytes-like object is required,not str': 问题出在python3.5和Python2.7在套接字返回值解码上有区别:python bytes和str两种类型可 ...

  2. js光标定位操作

    1. 自动选中区域内容 <html> <meta http-equiv="Content-Type" content="text/html; chars ...

  3. 【LEETCODE】47、985. Sum of Even Numbers After Queries

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  4. Computational biological hypothesis generation using "-omics" data

    Computational biological hypothesis generation using "-omics" data Forming biological hypo ...

  5. 使用交叉验证法(Cross Validation)进行模型评估

    scikit-learn中默认使用的交叉验证法是K折叠交叉验证法(K-fold cross validation):它将数据集拆分成k个部分,再用k个数据集对模型进行训练和评分. 1.K折叠交叉验证法 ...

  6. Part_two:Redis之发布订阅

    Redis发布订阅 发布订阅的命令 PUBLISH channel msg 将信息 message 发送到指定的频道 channel SUBSCRIBE channel [channel ...] 订 ...

  7. 设置 SQL*Plus 的运行环境

    SQL*Plus 的运行环境是用来输入.执行 SQL*Plus 命令和显示返回结果的场所,设置合适的 SQL*Plus 运行环境,可以使 SQL*Plus 按照用户的要求运行和执行各种操作.set 命 ...

  8. Java Runtime.exec()用法

    转自:https://www.cnblogs.com/mingforyou/p/3551199.html Java Runtime.exec()的使用 Sun的doc里其实说明还有其他的用法: exe ...

  9. Fortify漏洞之 Log Forging(日志伪造)

    继续对Fortify的漏洞进行总结,本篇主要针对 Log Forging(日志伪造)的漏洞进行总结,如下: 1.1.产生原因: 在以下情况下会发生 Log Forging 的漏洞: 1. 数据从一个不 ...

  10. Referenced file contains errors (xml文件第一行小红叉错误)

    转自:http://www.manongjc.com/article/30401.html 在eclipse中开发网页时,经常会遇到写xml文件时第一行无缘无故报错.在最左面的行数上面报出一个小红叉, ...