Skip to content

Commit 340a73a

Browse files
author
lanyuanxiaoyao
committed
修改文件: _posts/2015-06-04-find-prime-numbers.md
1 parent a39f057 commit 340a73a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
layout: post
3+
title: 1262.寻找素数对
4+
date: 2015-06-04 21:06
5+
categories: 杭电HDU
6+
tags: [杭电HDU,搜索]
7+
---
8+
## Problem
9+
>**Problem Description**
10+
哥德巴赫猜想大家都知道一点吧.我们现在不是想证明这个结论,而是想在程序语言内部能够表示的数集中,任意取出一个偶数,来寻找两个素数,使得其和等于该偶数.
11+
做好了这件实事,就能说明这个猜想是成立的.
12+
由于可以有不同的素数对来表示同一个偶数,所以专门要求所寻找的素数对是两个值最相近的.
13+
**Input**
14+
输入中是一些偶整数M(5<M<=10000).
15+
**Output**
16+
对于每个偶数,输出两个彼此最接近的素数,其和等于该偶数.
17+
**Sample Input**
18+
20 30 40
19+
**Sample Output**
20+
7 13
21+
13 17
22+
17 23
23+
24+
## Solution
25+
```cpp
26+
#include<stdio.h>
27+
#include<math.h>
28+
int sushu(int x)
29+
{
30+
int i;
31+
for(i=2;i<=sqrt(x);i++){
32+
if(x%i==0)return 1;
33+
}
34+
return 0;
35+
}
36+
int main(void)
37+
{
38+
int x,i;
39+
while(scanf("%d",&x)!=EOF){
40+
for(i=x/2;i>0;i--){
41+
if(sushu(i)==0&&sushu(x-i)==0)break;
42+
}
43+
printf("%d %d\n",i,x-i);
44+
}
45+
return 0;
46+
}
47+
```

0 commit comments

Comments
 (0)