题意:

克里斯蒂安·哥德巴赫曾经猜想,每个奇合数可以写成一个素数和一个平方的两倍之和

9 = 7 + 2×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12

最终这个猜想被推翻了。

最小的不能写成一个素数和一个平方的两倍之和的奇合数是多少?

思路:用线性筛法记录下来所有素数,然后去生成在范围内的哥德巴赫数字即可


/*************************************************************************
> File Name: euler046.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月29日 星期四 12时51分48秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h> #define MAX_N 100000 int32_t IsPrime[MAX_N + 10] = {0} , primeList[MAX_N + 10] = {0};
int32_t GoldbachNum[MAX_N + 10] = {0}; void Init() {
for (int32_t i = 2 ; i <= MAX_N ; i++) {
if (!IsPrime[i]) { primeList[ ++primeList[0] ] = i; }
for (int32_t j = 1 ; j <= primeList[0] ; j++) {
if (i * primeList[j] > MAX_N) break;
IsPrime[i * primeList[j]] = 1;
if (i % primeList[j] == 0) break;
}
}
for (int32_t i = 1 ; i <= primeList[0] ; i++) {
for (int32_t j = 1 ; true ; j++) {
if (primeList[i] + 2 * j * j > MAX_N) break;
GoldbachNum[primeList[i] + 2 * j * j] = 1;
}
}
}
int32_t main() {
Init();
for (int32_t i = 33 ; i <= MAX_N ; i += 2) {
if (!IsPrime[i]) continue;
if (!GoldbachNum[i]) {
printf("ans = %d\n",i);
break;
}
}
printf("end\n");
return 0;
}

Project Euler 46 Goldbach's other conjecture( 线性筛法 )的更多相关文章

  1. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  2. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

  3. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  4. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  5. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  6. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  7. project euler 169

    project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...

  8. IEEEXtreme 10.0 - Goldbach's Second Conjecture

    这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Goldbach's Second Conjecture 题目来源 第10届IEEE极限编程大赛 https ...

  9. 【Project Euler 8】Largest product in a series

    题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...

随机推荐

  1. UVALive Archive - 6196 - Party Games

    题目: You've been invited to a party. The host wants to divide the guests into 2 teams for party games ...

  2. 0918如何利用jmeter为数据库插入测试数据

    第一 制定测试计划,关于JMETER会通过驱动取操作数据库,因而请在底部路径填写正确. 下载该资源http://download.csdn.net/download/fnngj/3451945 第二步 ...

  3. [bzoj3717][PA2014]Pakowanie_动态规划_状压dp

    Pakowanie bzoj-3717 PA-2014 题目大意:给你n个物品m个包,物品有体积包有容量,问装下这些物品最少用几个包. 注释:$1\le n\le 24$,$1\le m\le 100 ...

  4. Android之后台启动Activity

    在实际开发中.Activity须要启动但界面又不能显示出来,这时就须要后台启动.但又不是finish(),这时就要用到Activity中的moveTaskToBack函数,先看下官网 參数nonRoo ...

  5. D3D triangle list(三角形列) 小样例

    画三角形列的样例程序 #pragma once #pragma comment(lib,"d3d9.lib") #pragma comment(lib,"d3dx9.li ...

  6. SICP 习题1.16-1.19体会

    首先反思一下, 昨天做1.14的时候犯了一个严重错误.思维定式了,导致花了非常多无用功. 1.14的关键是要想到2个物理意义. 一个是广度优先, 也就是仅仅考虑问题递归树的第一层子数.那么必定有公式 ...

  7. rar x 解压rar文件,提示permission denied

    问题: 解压rar文件,提示

  8. [SCOI 2010] 股票交易

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1855 [算法] 单调队列优化动态规划 [代码] #include<bits/s ...

  9. SQL Server的自动备份设置及排错记事

    1.启动 SQL Server Management Studio管理器,登录进去. 2.在左侧可以看到这个,我们展开“管理”. 3.展开“管理”后,我们在“维护计划”项目上单击右键,在弹出菜单里选择 ...

  10. C# 委托、事件

    委托(delegate) 访问修饰符 delegate 返回值类型 委托名 (参数列表) 委托是一种可以把引用存储为函数的类型,也就是说它声明了一种用于保存特定格式函数的数据类型,如图C++中的函数指 ...