POJ 2262 Goldbach's Conjecture

Goldbach`s Conjecture(线性筛法) Goldbach`s Conjecture LightOJ - 1259 Goldbach’s conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states: Every even integer, greater than 2, can be expr... 阅读详情

Goldbach's Conjecture
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 41506 Accepted: 15899

Description

In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:
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

The input will contain one or more test cases.
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

For each test case, print one line of the form n = a + b, where a and b are odd primes. Numbers and operators should be separated by exactly one blank like in the sample output below. If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized. If there is no such pair, print a line saying "Goldbach's conjecture is wrong."

Sample Input

8
20
42
0

Sample Output

8 = 3 + 5
20 = 3 + 17
42 = 5 + 37

//:poj2262 Goldbach's Conjecture
//import java.math.*;
import java.util.Scanner;
public class poj2262 {
	public static void main(String[] args)
	{
		final int n=1000010;
		int i,j;
		int[] num=new int[n];
		for(i=0;i<n;i++)
		num[i]=0;
		for(i=2;i<=Math.sqrt(n);i++)
		   for(j=i+i;j<n;j+=i)
		   if(num[j]==0)
		   num[j]=1;
		
//		for(i=0;i<50;i++)
//		System.out.printf("%d %d\n",i,num[i]);
		int m;
		boolean judge;
		Scanner input=new Scanner(System.in);
		while(true)
		{
			m=input.nextInt();
			if(m==0) break;
			for(i=2,judge=false;i<=m/2;i++)
			if(num[i]==0&&num[m-i]==0)
			{
				judge=true;
				break;
			}
			
			if(judge==true)
			System.out.printf("%d = %d + %d\n",m,i,m-i);
			else
			System.out.printf("Goldbach's conjecture is wrong.\n");
		}
		input.close(); 
	}
}
///:~

VUE3如何使得大屏自适应的几种方法? 16:9。 阅读详情

相关推荐

我用两个月时间,终于把CSDN付费资源项目玩明白了!

关于项目的定位,这是一个知识付费项目,根据市场研究机构的数据显示,到2023年,全球知识付费市场规模将达到2000亿美元,所以说知识付费的前景是十分广阔的,当下互联网时代信息大爆炸,80后、90后、00后群体对知识付费的认可度也大幅提升,同时这群作为知识付费的主流人群已经具备了更强的消费能力,而且对于知识付费的需求更高。目前整个知识付费领域仍然在发展起步的初期,尽快在知识付费领域布局可以帮助我们在这波红利中获得一份不错的收益。而且个人认为,

白话机器学习 2万+

哥德巴赫猜想-中文维基百科

哥德巴赫猜想-中文维基百科 哥德巴赫猜想(Goldbach’s conjecture) 是数论中存在最久的未解问题之一。这个猜想最早出现在1742年普鲁士人克里斯蒂安·哥德巴赫与瑞士数学家莱昂哈德·欧拉的通信中。用现代的数学语言,哥德巴赫猜想可以陈述为: 任一大于2的偶数,都可表示成两个素数之和。 这个猜想与当时欧洲数论学家讨论的整数分拆问题有一定联系。整数分拆问题是一类讨论“是否能将整数分拆...

zp235711的博客 1万+

实用工具系列 - Xshell安装下载与使用

一、介绍 二、下载 三、安装 四、使用

Passerby_Wang的博客 1万+

哥德巴赫猜想c语言 思路,01-哥德巴赫猜想(Goldbach's Conjecture)--(C语言)

goldbach-partitions-of-the-even.png前言哥德巴赫猜想是(Goldbach's Conjecture)是数论中存在最久的未解问题之一,是一个伟大的世界性的数学猜想,其基本思想可以陈述为:任何一个大于2的偶数,都能表示成两个素数之和。如:4 = 2 + 26 = 3 + 396= 23 + 73本文将采用两种不同的算法来求出给定范围 n 内的哥德巴赫数字,并对比其时间...

weixin_33601398的博客 3074

Arcgis填补栅格空缺值Nodata

Arcgis填补栅格空缺值Nodata

pass17的博客 1万+

RocketMq面板访问异常 com.alibaba.fastjson.JSONException: not close json text, token : string

rocketmq JSONException: not close json text, token : string 问题解决

qq_21067307的博客 5584

初阶java10_ 打印 1 - 100 之间所有的素数

// 打印 1 - 100 之间所有的素数 import java.util.Scanner; public class Demo_6{ public static void main(String[] args) { //录入一个数 System.out.println("请输入所求素数的范围:"); Scanner scan = new Scanner (System.in...

weixin_42536748的博客 812

详解电路设计中的RC电路

​ 一、什么是RC电路 RC电路是指由电阻R和电容C组成的电路,它是脉冲产生和整形电路中常用到 的电路。 常见的RC充、放电电路、RC积分电路合RC微分电路接下来详细讲解。 二、RC充、放电电路 RC充、放电电路如下图所示,下面通过充电和放电两个过程来分析此电路。 ​RC充、放电电路图 (1)RC充电电路 RC充电电路图如下图(a)所示 RC充电电路图及充电曲线图 ​由上图分析: 将上图a中开关S置于“1”处,电源E开始通过电阻R对电容C充电,由于刚开始充电时电容两端没有..

IT xiaobai 4万+

Goldbach's Conjecture-(两个素数判断就可解决的数学算法)

题意描述: 给一个偶数,让你分成两个素数(因为素数一定是奇数所以就不考虑奇数了)对于素数的要求是在分解的所有素数对中这两个素数差值最大(实际上只要从最小的素数找这句话就可以不用管)没找到就输出Goldbach’s conjecture is wrong.; 解题思路:为方便描述假设公式为s=n+m从最小的素数开始判断,要是找到了n,就判断m是不是素数如果是就直接输出n,m,不是的话就继续往下找下一...

weixin_44606952的博客 557

基于YOLOv5的人脸识别系统:从构建到应用的全流程指南

本文详细介绍了基于YOLOv5的人脸识别系统开发全流程。首先阐述了YOLOv5模型的高效性和准确性优势,随后分步骤讲解了深度学习环境配置、数据集准备(推荐WIDER FACE数据集)和模型训练方法。重点展示了如何将训练好的模型集成到Tkinter开发的GUI界面中,实现图片上传、人脸检测和结果可视化功能。文章提供完整的代码示例和飞书文档链接(密码:946m22&8),帮助开发者快速构建可交互的人脸识别系统,适用于安防、门禁等多种应用场景。通过该项目,读者可掌握YOLOv5的实际应用和界面集成技术。

FJN110的博客 181

基于单片机的智能温控风扇设计

该智能温控风扇系统的设计目标是根据环境温度自动控制风扇的转速或开关状态,确保用户始终处于舒适的温度范围内。实时温度监测:通过温度传感器(如DS18B20或DHT22)实时监控环境温度。风扇控制:根据温度变化自动调节风扇的转速,温度过高时风扇加速,温度适中时风扇转速降低,达到节能与舒适平衡。LCD显示:通过LCD屏幕实时显示温度信息。无线通信:通过Wi-Fi或蓝牙模块将温度数据发送至手机或云平台,支持远程控制风扇的开关或调节转速。报警功能:温度过高或过低时,蜂鸣器发出警报,提示用户注意。

2201_76125393的博客 1184

poj2262 Goldbach's Conjecture

poj2262 Goldbach's Conjecture 用欧拉筛把素数筛出来,再枚举一下。 #include<iostream> #include<cstdio> #include<cstring> #define re register using namespace std; #define N 1000001 int ...

dingqiongliang0363的博客 174

Dify 第 13 篇 Dify 工作流 详解

工作流通过将复杂任务分解为节点降低复杂度,提升LLM应用的性能和稳定性。Dify工作流分为两类:Chatflow面向对话场景(如客服),支持多轮对话;Workflow面向批处理场景(如翻译),提供逻辑节点实现自动化。核心概念包括节点、变量(系统/会话/环境变量)及应用类型差异:Chatflow支持中间输出和对话历史,Workflow仅支持结束节点输出。系统变量以"sys"开头,用于全局数据传递,不同应用类型变量不同,如Chatflow的sys.query存储用户输入,Workflow的s

甘蓝的专栏 3280

poj 2262 Goldbach's Conjecture

poj  2262  Goldbach's Conjecture                题目链接:http://poj.org/problem?id=2262 数学水 background knowledge:哥德巴赫猜想,每个合数都能写成两个质数之和的形式。 题目大意:验证百万以内哥德巴赫猜想的正确性(还好是验证不是证明,不然就要请景润先生吃个饭了)。 题目分析:简单的素数打表就

slicer的技术交流栈 712

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Poj 2262 Goldbach's Conjecture

Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41987   Accepted: 16061 Description In 1742, Christian Goldbach, a German amateur mathe

曾经沧海难为水,除却巫山不是云 449

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ-2262 Goldbach's Conjecture

题意:给定一个偶数n,将其分解成两个素数(有多组则输出差值最大的)。 思路:水水....... 题目链接:http://poj.org/problem?id=2262 View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #inc...

bancaidun1539的博客 138

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

POJ - 2262:Goldbach's Conjecture

In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of...

weixin_37992828的博客 175

poj——2262——Goldbach's Conjecture

Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture:  Every even number greater than 4 can be  writt

清溪浅水 697

POJ2262:Goldbach's Conjecture

Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written

ACM!荣耀之路! 3077

POJ 2262 Goldbach's Conjecture

Problem Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be

谙忆-陈浩翔 1960

poj2262-Goldbach's Conjecture

http://poj.org/problem?id=2262 #include #include #include #include #include #include using namespace std ; #define INT long long INT judge( INT n ) { if( n % 2 == 0 ) return 0 ; else { for(

bo-jwolf的专栏 1224

POJ2262 Goldbach's Conjecture

2262:Goldbach's Conjecture 题目分析: 一百万个数,开辟一个数组用于标识是否是素数,用bool型表示,总内存小于1M,然后查表即可。建立素数表,对每个素数,把该素数的所有倍数所在的位置都置为false。 代码如下: 1048kB 50ms688 B #include int main(){ bool primeMap[1000000];

moonswap的博客 722
上一篇: java中equals方法的用法以及==的用法
下一篇: POJ 1503 Integer Inquiry
SimonCoder
博客等级 码龄13年 1414粉丝 231原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址