Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)
题意:
就是哥德巴赫猜想。。。任意一个偶数 都可以分解成两个(就是一对啦)质数的加和
输入一个偶数求有几对。。
解析:
首先! 素数打表。。因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质数 。。。 我真是蠢啊
还有 vis要用bool类型的!!!! int会直接爆
代码如下:
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 10000000
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;
LL primes[];
bool vis[maxn];
int cnt = ;
void init()
{
mem(vis,);
primes[] = ; primes[] = ;
for(int i=; i<maxn; i++)
if(!vis[i])
{
primes[cnt++] = i;
for(LL j=(LL)i*i; j<maxn; j+=i)
vis[j] = ;
}
} int main()
{
int T;
init();
int res = ;
cin>> T;
while(T--)
{
int ans = ;
int n;
cin>> n;
for(int i=; i<cnt && primes[i] <= n/; i++)
{
if(!vis[n-primes[i]])
ans++;
}
printf("Case %d: %d\n",++res,ans); } return ;
}
Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)的更多相关文章
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- Lightoj 1370 素数打表 +二分
1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Time Limit: 2 second(s) Memory Limit: 32 MB ...
- Light oj-1259 - Goldbach`s Conjecture
1259 - Goldbach`s Co ...
- 哥德巴赫猜想-nefu2 & 分拆素数和 hdu2098
哥德巴赫猜想-nefu2 & 分拆素数和 hdu2098 //哥德巴赫猜想 #include <iostream> #include <cmath> #include ...
- LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- HDU 1397 Goldbach's Conjecture【素数打表】
题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...
- LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...
随机推荐
- LVDS时序分析
LVDS时序分析 2012年05月07日 11:48:08 Walle 阅读数:3355 标签: 平台工作 最近在调试基于telechip平台的LVDS驱动,一开始对该平台的LVDS时序不是很了解 ...
- 深入理解 JS 引擎执行机制(同步执行、异步执行以及同步中的异步执行)
首先明确两点: 1.JS 执行机制是单线程. 2.JS的Event loop是JS的执行机制,深入了解Event loop,就等于深入了解JS引擎的执行. 单线程执行带来什么问题? 在JS执行中都是单 ...
- Android 真机调试
/************************摘抄*****************************/ 刚好遇到这个问题,在网上百度了一下,看到有人分享了引起该问题的几个原因: 1.手机设 ...
- cp 命令有坑
cp 是个很常用的命令, 基本语法为 cp -v a b 把文件a 复制为文件b(-v为显示做了什么,这是非常安全的做法,建议新手添加此参数) 参数说明: -a:此选项通常在复制目录时使用, ...
- 发布了一个基于jieba分词的ElasticSearch插件
github地址: https://github.com/hongfuli/elasticsearch-analysis-jieba 基于 jieba 的 elasticsearch 中文分词插件. ...
- PowerBI开发 第十五篇:DAX 表达式(时间+过滤+关系)
DAX表达式中包含时间关系(Time Intelligence)相关的函数,用于对日期维度进行累加.同比和环比等分析.PowerBI能够创建关系,通过过滤器来对影响计算的上下文. 一,时间关系 DAX ...
- Qt Creator 中,如何更改h,cpp,ui的文件并不让ui失效
这个星期在使用qt,碰到一个很蛋疼的问题:创建对话框的时候,不小心输错了名字.而且是在很迟才发现的.这个时候对话框都已经布局差不多了,为了改名字,碰到更蛋疼的问题,改了名字后就无法使用转到槽的功能了. ...
- gerrit代码简单备份方案分享
由于前期部署了gerrit代码审核系统,开发调整后的线上代码都放到gerrit上,这就要求我们要保证代码的安全.所以,对gerrit代码的备份至关重要! 备份的策略是:1)先首次将gerrit项目代码 ...
- kvm虚拟化管理平台WebVirtMgr部署-完整记录(3)
继下面三篇文章完成了kvm虚拟化管理平台webvirtmgr环境的部署安装:kvm虚拟化管理平台WebVirtMgr部署-虚拟化环境安装-完整记录(0)kvm虚拟化管理平台WebVirtMgr部署-完 ...
- [BUAA-SE-2018]结对作业测试报告
目录 1. 测试方式 2. 评分规则 2.1 测试点组成 2.2 性能测试的分级 2.3 重新提交的扣分策略 3. 评测结果 3.1 罗老师班 3.2 任老师班 3.3 表中数据的说明 4. 测试点下 ...