Project Euler:Problem 46 Goldbach's other conjecture
2015-06-07 10:04
423 查看
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.
9 = 7 + 2×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
9 = 7 + 2×12
15 = 7 + 2×22
21 = 3 + 2×32
25 = 7 + 2×32
27 = 19 + 2×22
33 = 31 + 2×12
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
#include <iostream> using namespace std; bool isPrime[1000010]; bool gold(int n) { for (int i = 2; i < n; i++) { if (isPrime[i] == true) { int tmp = n - i; //cout << i << " " << tmp << endl; if (tmp % 2 == 0) { int k = sqrt(tmp / 2); if (k*k == tmp / 2) return true; } } } return false; } int main() { memset(isPrime, true, sizeof(isPrime)); for (int i = 2; i <= 1010; i++) { if (isPrime[i]) { for (int j = 2; j*i < 1000010; j++) { isPrime[i*j] = false; } } } //int a = gold(15); for (int i = 2; i <= 1000000; i++) { if (isPrime[i] == false && i % 2 == 1) { if (!gold(i)) { cout << i << endl; break; } } } system("pause"); return 0; }
相关文章推荐
- 浅谈Google File System
- POJ 1042 Gone Fishing
- google验证码 kaptcha 的使用
- 学习django-1
- x2go
- ubuntu 如何安装sougou(搜狗)输入法 亲测好用
- golang grpc thrift with aerospike
- 漫步云端之初读Google三大论文(一)
- 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II
- Django学习日记02_项目环境
- 2015 GOOGLE I/O大会看点总结:新的开发工具及云端测试工具
- Django学习日记01_环境搭建
- hdu 1847 Good Luck in CET-4 Everybody!
- django环境搭建
- unbuntu 14安装 golang
- Go语言文档
- hdu 1864 最大报销额 (01背包)
- Google photos -- reverse thinking
- 各个屏幕的logo尺寸要求
- UVA 11292 DRAGON OF LOOWATER 【贪心】