当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
- Switch node version and switch npm source tool
- 华为WLAN技术:AP上线及相关模板的配置实验
- 二叉树的前序遍历
- JS手写JSON.stringify() (面试)
- Go study notes (Part 1) Configuring the Go development environment
- visual studio 与 visual studio code
- 《支付宝体验设计精髓》一书,跟测试相关性知识记录
- Client Side Cache 和 Server Side Cache 的区别
- 【Attention 演变史】RNN的产生、架构、推广、问题(第一弹)
- 如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
猜你喜欢

02 ts 变量定义,类型

VQ Realization of Wavelet Extraction Features

Regular expression is incomplete

Dragoma (DMA) Metaverse System Development

03 ts类型缩小,函数

【Attention 演变史】RNN的产生、架构、推广、问题(第一弹)

hash和history路由的区别

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

基于YOLOV5行人跌倒检测实验

The list of Kubernetes - watch mechanism
随机推荐
How to manually download and install SAP Fiori tools - Extension Pack for Visual Studio Code
really time ntp service start command
If it is test axi dma catch a few words here
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
The list of Kubernetes - watch mechanism
SIGIR 2022 | 邻域建模Graph-Masked Transformer,显著提高CTR预测性能
程序员如何在职场上少走弯路?
How to use the Chrome DevTools performance tab
zynq 记录
Highlights of some performance tests
A complete cross-compilation environment records the shell scripts generated by peta
华为企业组网实例:VRRP+MSTP典型组网配置
红外图像滤波
really time ntp服务启动命令
正畸MIA微种植体支抗技术中国10周年交流会在沈举办
Polygon zkEVM 基本概念
JSD-2204-酷莎商城(管理员模块)-密码加密-Day10
Defaced Fingerprint Recovery and Identification
[Latest Information] 2 new regions will announce the registration time for the soft exam in the second half of 2022
华为交换机:STP测试实验