K - Goldbach's Conjecture解题报告(陈渊)

HOJ1459 Goldbach's Conjecture Goldbach's Conjecture My Tags   (Edit)   Source : University of Ulm Internal Contest 1998   Time limit : 1 sec   Memory limit : 32 M 阅读详情

K - Goldbach's Conjecture
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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

这题超时了N遍,就是不记得筛选法求素数了,哎~~~这次可要牢记了,其他的就不多说了。。。

[cpp]  view plain copy
  1. #include<iostream>  
  2. #include<time.h>  
  3. short prime[1000000];  
  4. using namespace std;  
  5. int main()  
  6. {  
  7.     int i,j,s=0,n,num;  
  8.     memset(prime,0,sizeof(prime));  
  9. for(i=2;i<1000000;i++)  
  10. for(j=2;i*j<1000000;j++)  
  11. {  
  12.     if(prime[i*j]==0)  
  13.         prime[i*j]=1;  
  14. }  
  15.     while(scanf("%d",&n)&&n!=0)  
  16.     {  
  17.             for(i=3;i*2<=n;i+=2)  
  18.                 if(prime[i]==0&&prime[n-i]==0)  
  19.                 {  
  20.                     printf("%d = %d + %d\n",n,i,n-i);  
  21.                     goto end;  
  22.                 }  
  23.                 printf("Goldbach's conjecture is wrong.\n");  
  24. end:;  
  25.     }  
  26.   
  27.     return 0;  
  28. }  




Docker拉取ubuntu22.04镜像使用ROS2 humble及仿真工具可视化进行导航 Docker中安装Ubun22以及ROS,gazebo可视化等 阅读详情

相关推荐

F5 GTM DNS 实战指南:智能DNS的监控与健康检查机制

本文深入解析F5 BIG-IP GTM智能DNS的核心机制,重点阐述其监控与探针两大功能如何协同工作。监控器负责深度检查服务器应用健康,确保服务可用性;探针则实时测量网络路径质量,实现基于延迟的智能流量调度。文章通过实战配置步骤,指导如何构建逻辑架构、建立iQuery通信、配置业务级健康检查及探针,从而构建高可用、高性能的全局负载均衡解决方案。

weixin_29240711的博客 468

poj-2262 Goldbach's Conjecture

题目链接:http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28046   Accepted: 10797 Description In 174

小雨的专栏 747

解决Windows 10安装语言包时遇到的0x800F0954错误

在安装Windows 10操作系统的语言包时,如果遇到错误代码0x800F0954的提示,这无疑会让许多用户感到困惑和无助。这个错误通常意味着在安装过程中遇到了一些阻碍,导致无法正常完成语言包的安装。本文将为大家详细解析这个错误代码0x800F0954,并提供一系列有效的解决方法,帮助大家顺利安装所需的语言包。

nntxthml的博客 3793

【题解】LibreOJ10200 Goldbach's Conjecture 线性筛

题目链接 题目描述 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于 444 的偶数都可以拆成两个奇素数之和。 比如: 8=3+520=3+17=7+1342=5+37=11+31=13+29=19+238=3+5\quad20=3+17=7+13\quad42=5+37=11+31=13+29=19+238=3+520=3+17=7+1342=5+37=11+31...

翻过这座山,他们就会听到你的故事 286

百度API实现人流量数量检测(动态)

百度的这个API还挺好用的,对与不追求高精度的人来说非常适用,结合他官方给的文档,极易上手。 需要做的就是通过API Key和Secret Key获取的access_token。 然后稍微修改下代码就行,但是他给的代码并没有直接从摄像头获取视频,而是读取一个文件夹,那么就需要自己先对摄像头的输出视频进行处理。 识别结果如下,"person_num"是当前画面的人数,in是累计进入的人数,out是累计走出去的人数。 他这个有个缺点就是返回值里边并没有实时返回in和out的值,而是都是0,但是这个图片上有,图片

qq_42479987的博客 3379

X3850x6 6241 fireware固件升级

登录联想https://datacentersupport.lenovo.com/cn/zc网站,选择system x,x3850 x6,type选择6241 选择驱动及应用程序,BIOS/UEFI 选择lnvgy_fw_uefi_a9e156a-4.90_anyos_32-64.uxz 文件,点击下载 选择IMM2, 下载lnvgy_fw_imm2_tcoo58b-5.80_anyos_noarch.uxz ps:3837和3839会跳转到ibm网站下载 笔记本直连.

zds00virtue的博客 5452

Goldbach's Conjecture

题目描述 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于4的偶数都可以拆成两个奇素数之和。 比如: 8=3+5 20=3+17=7+13 42=5+37=11+31=13+29=19+23 你的任务是:验证小于 的数满足哥德巴赫猜想。 输入 多组数据,每组数据一个n。 读入以0结束。 输出 对于每组数据,输出形如n = a + ...

算法小猪的博客 1452

使用Anaconda和conda快速搭建YOLO开发环境

本文详细介绍了如何使用Anaconda和conda为YOLO目标检测项目快速搭建独立、纯净的开发环境。通过创建虚拟环境,有效解决了Python包版本冲突和CUDA兼容性问题,并指导安装GPU版PyTorch等核心依赖,最后通过验证脚本确保环境配置成功,为YOLO开发提供了稳定可靠的基础。

weixin_28829629的博客 161

POJ2262.Goldbach's Conjecture(哥德巴赫的猜想)

【题意】 哥德巴赫猜想:大于四的偶数可以分解为两个奇素数之和 对于给出的数n,如果有多对奇数素数加起来为n,则选择差值b-a最大化的。 若没有这样的一对,则打印"Goldbach's conjecture is wrong." 【思路】 枚举:直接枚举所有的,看是否符合条件,从小到大枚举到中间的话符合条件的也就是差值最大的 #include<stdio.h> #include...

428

Yolo8行人车辆目标检测实战分享 完整项目代码可直接运行

Yolo8行人车辆目标检测实战分享 完整项目代码可直接运行

1293

《Python等级认证CCF-GESP真题解析》专栏总目录

❤️ 专栏名称:《🌸 专栏介绍:中国计算机学会GESP《CCF编程能力等级谁》Python编程(1~8级)历届真题解析。🚀 订阅专栏:订阅后可阅读专栏内所有真题解析,真题持续更新中,限时9.9元,欢迎订阅!

人生就是一个不断学习的过程 1878

URAL 1356 哥德巴赫猜想

题意:给出一个数,把它分解成几个素数相加的形式,要求分解出的素数的数量最小。 这题分情况讨论就可以了,首先需要知道哥德巴赫猜想即一个大于4的偶数可以分解成两个素数和的形式。其次需要知道奇数加奇数等于偶数,奇数减奇数等于偶数。 那么首先判断n是否是素数,如果是直接输出n就可以。 接下来判断如果n是奇数,那么先判断n-2是否是素数,如果是的话那么最小数量的素数和即n-2 与 2,如果不是那么肯定

韩小侠的专栏 已迁移至lssea.com 958

Codex 接入国产大模型完整指南:CC-Switch 与 Codex++ 的工程化选型

Codex 默认走 OpenAI Responses API,而 DeepSeek、GLM、Kimi 等国产模型只提供 OpenAI-compatible 的 Chat Completions——两套协议在消息结构、流式响应、reasoning 字段、tool call 上都不兼容,所以"改个 Base URL + 填国产 Key"这种朴素操作根本跑不通。本文从架构师视角出发,把 Codex 接入国产大模型这件事讲透:先剖析协议链路到底卡在哪,再对比 CC-Switch和 Codex++两套主流方案的差异

少说,多做 3850

一本通1622Goldbach’s Conjecture

1622:Goldbach’s Conjecture 时间限制: 1000 ms 内存限制: 524288 KB 【题目描述】 原题来自:Ulm Local,题面详见:POJ 2262 哥德巴赫猜想:任何大于44的偶数都可以拆成两个奇素数之和。 比如: 8=3+5 20=3+17=7+13 42=5+37=11+31=13+29=19+23 你的任务...

weixin_30293079的博客 416

假人有限元模型

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

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

翻译题寒假第一次周赛签到题8

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. 【描述:在1742年, Christia

Abby_yyyyyyy的博客 390

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

英语题翻译6

Goldbach's Conjecture | JXNUOJ 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. F

zanhhhhhh的博客 452

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

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 writ

谢庆皇的专栏 861

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的专栏 1223

Goldbach`s Conjecture

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 expressed as the sum of two primes [1].

wanghandou的博客 483

HDU 1397 Goldbach's Conjecture

Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3322    Accepted Submission(s): 1213 Problem Description Goldba

闲暇时光写代码 853

线性筛 - Goldbach‘s Conjecture - POJ 2262

线性筛 - Goldbach’s Conjecture - POJ 2262 题意: 哥德巴赫猜想的内容如下: 任意一个大于 4 的偶数都可以拆成两个奇素数之和。 例如: 8=3+5 20=3+17=7+13 42=5+37=11+31=13+29=19+23 现在,你的任务是验证所有小于一百万的偶数能否满足哥德巴赫猜想。 输入格式 输入包含多组数据。 每组数据占一行,包含一个偶数 n。 读入以 0 结束。 输出格式 对于每组数据,输出形如 n = a + b,其中 a,b 是奇素数。 若有多组满足条件的

njuptACMcxk的博客 218

杭电 1397 水题

一道很水的题,题目: Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2805    Accepted Submission(s): 1040 Problem Des

1297

POJ 2262 Goldbach's Conjecture

初看这题非常的眼熟,嗯,没错,我在UVa上刷过啊~ 马上去找源码,欢喜的打开,结果发现是个半成品代码 =_=# 查了下uHunt结果发现这题连提交都没提交过……咳咳…… 没有关系,正好最近get了新技能——筛法求素数,正好拿来实验一番~ 这题考的可是大名鼎鼎的哥德巴赫猜想:任一大于2的偶数都能写成两个质数之和。 思路:先打个质数表,再从头判断 i 和 (n-i) 是否同时为素数。

Uni ACM 1212

POJ2262

POJ2262题解 POJ2262 解题重点在如下几个地方 1> 快速判断一个数是不是素数 2> 找出某个数前后两个素数 3> 判断差是不是素数(找素数对部分代码的主要逻辑) SOURCE 质量 Problem: 2262 User: 20132430222 Memory: 8836K Time: 657MS Language: C++ Re

MIIEo 642

POJ-2262 Goldbach's Conjecture 解题报告(数论) 哥德巴赫的猜想

连接--K -Goldbach's Conjecture Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u Description In 1742, Christian Goldbach, a German amateur mathematician, sent a lette

潘卓夫 997

题解: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 tw...

晚安( ̄o ̄) . z Z 342
上一篇: J - Perfect Pth Powers解题报告(陈渊)
下一篇: B - 反正切函数的应用解题报告(张宇)
CSUST_ACM
博客等级 码龄15年 42粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值