当前位置:网站首页>刷题-洛谷-P1304 哥德巴赫猜想
刷题-洛谷-P1304 哥德巴赫猜想
2022-08-04 19:44:00 【宋向上_UP】
P1304 哥德巴赫猜想-C语言
1、题目

2、解题过程
结果:
代码:
//洛谷 P1304 哥德巴赫猜想
#include <stdio.h>
//求质数
int prime(int a) {
int i;
if (a == 2) {
return 1;//表示是质数
}
for (i = 2; i < a; i++) {
//辗转相除
if (a % i == 0) {
break;
}
}
if (i >= a) {
return 1;//表示是质数
}
else {
return 0;//表示不是质数
}
}
int main() {
int n;//输入的偶数N 4≤N≤10000
int i, j;
int temp;
//int flag=0;
int p_1, p_2;//用于接收是否为质数
scanf_s("%d", &n);//正偶数
for (i = 4; i <= n; i = i + 2) {
//偶数
//flag = 0;
for (j = 2; j < i; j++) {
/* if (flag == 1) { break; }*/
temp = i - j;
p_1 = prime(j);
p_2 = prime(temp);
if (p_1 == 1 && p_2 == 1) {
//都是质数
if (i == n) {
printf("%d=%d+%d", i, j, temp);
}
else {
printf("%d=%d+%d\n", i, j, temp);
}
//flag = 1;
break;
}
}
}
return 0;
}
边栏推荐
- 如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
- IIC驱动OLED
- 目标检测的发展与现状
- Regular expression is incomplete
- 小软件大作用 | 如何省时省力进行Gerber图层快速对比?
- Quantitative trading robot system development
- SQL Server 遇到报错解决办法--更新中
- 如何推动乡村振兴的落地
- ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
- 华为WLAN技术:AP上线及相关模板的配置实验
猜你喜欢

华为WLAN技术:AP上线及相关模板的配置实验
Force KouTi (5), the longest text string back

openharmony代码框架初识(2)

Ant Group's time series database CeresDB is officially open source

SQL Server 遇到报错解决办法--更新中

Use "green computing" technology to promote sustainable development of computing power

小波提取特征的VQ实现

Openharmony code framework (2) the person that

PG网络传输安全SSL介绍及使用示例

Regular expression is incomplete
随机推荐
使用.NET简单实现一个Redis的高性能克隆版(二)
面试官:JVM运行时数据区包含哪几部分?作用是啥?
awk statistical average max min
To -.-- -..- -
awk statistical difference record
C#弹出询问对话框
二叉树的前序遍历
入门:人脸专集1 | 级联卷积神经网络用于人脸检测(文末福利)
nr part calculation
zynq 记录
按需视觉识别:愿景和初步方案
Embrace the Cmake child is simple and practical, but inflexible
电脑一键重装系统内存完整性无法打开怎么办
MMDetection 使用示例:从入门到出门
使用 Chrome 开发者工具的 lighthouse 功能分析 web 应用的性能问题
Spark提交参数说明和常见优化
T+Cloud:构建新型生意社交网络和营销关系的“智公司”
Go study notes (Part 1) Configuring the Go development environment
Zip4j使用
zynq records