Goldbach's Conjecture
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Every even number greater than 4 can be
written as the sum of two odd prime numbers.
For example:
8 = 3 + 5. Both 3 and 5 are odd prime numbers.
20 = 3 + 17 = 7 + 13.
42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.
Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.)
Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.
Input
Each test case consists of one even integer n with 6 <= n < 1000000.
Input will be terminated by a value of 0 for n.
Output
Sample Input
8
20
42
0
Sample Output
8 = 3 + 5
20 = 3 + 17
42 = 5 + 37
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
bool isprime ( int k )
{
int t = sqrt ( k + 0.5 ) ;
for ( int i = ; i <= t ; i ++ )
if ( k % i == )
return false ;
return true ;
}
int main()
{
// freopen ("a.txt" , "r" , stdin );
int n ;
while ( scanf ("%d", &n) , n )
{
int i ;
int t = n / ;
for ( i = ; i <= t ; i += )
if ( isprime ( i ) && isprime ( n - i ) )
break ;
printf ( "%d = %d + %d\n" , n , i , n - i ) ;
}
return ;
}
n = isprime(i) + isprime(n - i)
Goldbach's Conjecture的更多相关文章
- 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 ...
- UVa 543 - Goldbach's Conjecture
题目大意:给一个偶数,判断是否是两个素数的和. 先用sieve方法生成一个素数表,然后再进行判断即可. #include <cstdio> #include <vector> ...
- 【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 参考代码: ...
- Goldbach`s Conjecture(素筛水题)题解
Goldbach`s Conjecture Goldbach's conjecture is one of the oldest unsolved problems in number theory ...
随机推荐
- bower入门
一.bower简介 bower是一个基于js的包管理工具,类似于java的maven. 官方网站:http://bower.io/ 二.安装bower 使用bower,首先要安装node npm和gi ...
- C# 无法识别的转义序列
解决这个问题头两种方法:1.加个"\"进行转义:2.在前面加个@ 示例:我要进入D盘下video文件夹中的ysxs文件夹,写法分别为: D:\\video\\ysxs @" ...
- js中的DOM操作(2)
1.表格的更加与删除 <!DOCTYPE html> <html> <head> <title>表格操作</title> <style ...
- 如何在VMWare Workstation实现虚拟机与真机的文件共享
1.进入虚拟机的配置选项 进入方法有三种,一种是使用快捷键Ctrl+D,第二种是先右键点击虚拟机再选择Settings选项,第三种是点击快捷栏中的VM后选择Settings选项,后两种方法的截图如下. ...
- 基于Bootstrap的jQuery开关按钮插件
按钮 下载 使用方法 首先要在页面中引入依赖文件: jquery.Bootstrap.Bootstrap Switch CSS和Bootstrap Switch JS.这里用的是bootstr ...
- Html-input文本框只能输入数字
onKeyPress="if ((event.keyCode < 48 || event.keyCode > 57)) event.returnValue = false;&qu ...
- sql-in和not in
IN .NOT IN这个指令可以让我们依照一或数个不连续 (discrete) 的值的限制之内抓出数据库中的值 in和not in in:存在与...里面的 not in:不存在与..里面的 其指令语 ...
- 缓存插件 Spring支持EHCache缓存
Spring仅仅是提供了对缓存的支持,但它并没有任何的缓存功能的实现,spring使用的是第三方的缓存框架来实现缓存的功能.其中,spring对EHCache提供了很好的支持. 在介绍Spring的缓 ...
- Lucene 4.7 --创建索引
Lucene的最新版本和以前的语法或者类名,类规定都相差甚远 0.准备工作: 1). Lucene官方API http://lucene.apache.org/core/4_7_0/index.htm ...
- JEECMS页面中常用标签
(1)在段落前给每一行加序号 从0开始:${a_index}从1开始:${a_index+1} (2)标记说明 [文章导航]:[@cms.Position /] [文章标题]:${arti.title ...