问题标题: 酷町堂:酷町堂:3823 30分

0
0
已解决
金志成
金志成
资深守护
资深守护

3823   找质数对

题目描述 Description

对一个正整数n(4<=n<=1000),有多少对质数的和等于这个正整数?找出符合条件的质数对的数量。

输入描述 Input Description

输入一个正整数n

输出描述 Output Description

输出一个正整数,表示符合条件的质数对的数量,没有则输出0

样例输入 Sample Input

 

10

样例输出 Sample Output

 

2

数据范围及提示 Data Size & Hint

共有2对质数的和为10:(5,5)和(3,7)

 

 

 

#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[1005];
int main()
{           
    int n,s=0,c=5;
    cin>>n;
    a[1]=2;
    a[2]=3;
    a[3]=5;
    a[4]=7;
    for(int i=8;i<=1000;i++){
        if(i%2!=0&&i%3!=0&&i%5!=0&&i%7!=0){
            a[c]=i;
            c++;
        }
    }
    for(int i=1;i<=231;i++){
        for(int j=i;j<=231;j++){
            if(n==a[i]+a[j]){
                s++;
            }
        } 
    }
    cout<<s;
    return 0;
} 

这是我的代码 只有30分

大佬们帮帮忙吧


0
我要回答