两个质数的和是S,求这两个数最大的积

#include <bits/stdc++.h>
using namespace std;
bool Sushu(int a)
{
    for(int y=2;y<=a-1;++y)
    {
        if(a%y==0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    int n,s=0,a=0,d;
    cin>>n;
    if(n%2==0)
    {
        d=n;
    }
    else
    {
        d=n+1;
    }
    for(int i=1;i<=d/2;++i)
    {
        if(Sushu(i)&&Sushu(n-i))
        {
            s=i*(n-i);
            if(s>a)
            {
                a=s;
            }
        }
    }
    cout<<a;
    return 0;
}
posted @ 2022-10-30 21:34  四面楚歌2022  阅读(245)  评论(0)    收藏  举报