HDU1262-寻找素数对

 1 //#include<bits/stdc++.h>
 2 #include<map>
 3 #include<cstdio>
 4 #include<string>
 5 #include<cmath>
 6 #include<iostream>
 7 using namespace std;
 8 int zhishu(int x){
 9     if(x==2||x==3){
10         return 1;
11     }
12     else{
13         int tmp = (int)sqrt(x);
14         if(x%2==0){
15             return 0;
16         }
17         for(int i=3;i<=tmp;i+=2){
18             if(x % i==0)
19                 return 0;
20         }
21         return 1;
22     }
23 }
24 int main(){
25     int M;
26     while(scanf("%d",&M)!=EOF){
27         for(int i=M/2;i>=3;--i){
28             if(zhishu(i)==1 && zhishu(M-i)==1){
29                 printf("%d %d\n",i,M-i);
30                 break;
31             }
32         }
33     }
34 
35 
36 
37     return 0;
38 }

 

posted on 2019-03-21 14:48  孤笑  阅读(342)  评论(0编辑  收藏  举报