UVa 543 - Goldbach's Conjecture
题目大意:给一个偶数,判断是否是两个素数的和。
先用sieve方法生成一个素数表,然后再进行判断即可。
#include <cstdio>
#include <vector>
#include <bitset>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
#define MAXN 1000000 vi primes;
bitset<MAXN+> bs; void sieve(ll upper)
{
bs.set();
bs.set(, false);
bs.set(, false);
for (ll i = ; i <= upper; i++)
if (bs.test((size_t)i))
{
for (ll j = i*i; j <= upper; j += i)
bs.set((size_t)j, false);
primes.push_back((int)i);
}
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
sieve(MAXN);
int n;
while (scanf("%d", &n) && n)
{
int idx = ;
bool ok = false;
while (primes[idx] * <= n)
{
int t = n - primes[idx];
if (bs.test((size_t)t))
{
ok = true;
break;
}
idx++;
}
if (ok) printf("%d = %d + %d\n", n, primes[idx], n-primes[idx]);
else printf("Goldbach's conjecture is wrong.\n");
}
return ;
}
UVa 543 - Goldbach's Conjecture的更多相关文章
- 素数筛 uva 543
给你一个n求出n由2个奇质因子的和 这2个因子差最大 没有就输出'Goldbach's conjecture is wrong. #include<stdio.h> #include&l ...
- Goldbach's Conjecture
Goldbach's Conjecture Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- Goldbach's Conjecture(哥德巴赫猜想)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- 【LightOJ1259】Goldbach`s Conjecture(数论)
[LightOJ1259]Goldbach`s Conjecture(数论) 题面 Vjudge T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方 ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
- 题目1440:Goldbach's Conjecture(哥达巴赫猜想)
题目链接:http://ac.jobdu.com/problem.php?pid=1440 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
随机推荐
- Contest - 多校训练(985专场) Problem C: 985的方格难题
题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1157&pid=2 Description 985走入了一个n * n的方格地图, ...
- MySQL 建表
SET NAMES utf8; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for ` ...
- angularjs三级联动
<div ng-controller="AjaxCtrl"> <h1>AJAX - Oriented</h1> <div> Coun ...
- Linux RAR 安装和使用
描述:Linux默认自带ZIP压缩,最大支持4GB压缩,RAR的压缩比大于4GB. 流程:下载 >安装 > 使用 ------------------------------------- ...
- JavaBean--简介及基本使用
JavaBean本身就是一个类,属于java的面向对象编程 JavaBean是使用java语言开发的一个可重用的组建,在JSP开发中如果要应用JSP提供的JavaBean标签来操作简单的类的话,需要满 ...
- jvisualvm
f the fonts used by VisualVM are hard to read, switching the LaF might help. Try for example 'visu ...
- 消除SDK更新时的“https://dl-ssl.google.com refused”异常--(转)
SDK更新时的“https://dl-ssl.google.com refused”错误 Download interrupted: hostname in certificate didn't ma ...
- android 1.6 launcher研究之自定义ViewGroup (转 2011.06.03(二)——— android 1.6 launcher研究之自定义ViewGroup )
2011.06.03(2)——— android 1.6 launcher研究之自定义ViewGroup2011.06.03(2)——— android 1.6 launcher研究之自定义ViewG ...
- hadoop2.2 datanode 启动不了
FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed for block pool Block po ...
- RSA非对称加密Java实现
原文 加密基础方法类 import java.security.MessageDigest; import sun.misc.BASE64Decoder; import sun.misc.BASE64 ...