3 条题解

  • 0
    @ 2023-2-2 16:02:11

    筛完质数就差不多做完了

    #include <iostream>
    #include <stack>
    #include <cmath>
    #include <vector>
    #include <string.h>
    #include <queue>
    #include <stdio.h>
    #include <iomanip>
    #include <cstdio>
    #include <algorithm>
    #define int long long
    using namespace std;
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    int s;
    bool prime[N];
    void find_prime(int x)
    {
        prime[1] = 1;
    	for(int i = 2; i * i <= x; i++)
    	{
    		if(prime[i] == 0)
    		{
    			for(int j = i * i; j <= x; j += i)
    			{
    				prime[j] = 1;
    			}
    		}
    	}
    }
    signed main()
    {
        int s;
        cin >> s;
        find_prime(s);
        if(s % 2 == 1)
        {
            cout << 2 * (s - 2) << endl;
            return 0;
        }
        int maxx = -INF;
        for(int i = 1; i <= s; i++)
        {
            if(prime[i] == 0)
            {
                if(prime[s - i] == 0)
                {
                    maxx = max(maxx, i * (s - i));
                }
            }
        }
        cout << maxx << endl;
    	return 0;
    }
    
    • -1
      @ 2023-4-1 20:33:25
      #include<iostream>
      using namespace std;
      int n,maxx=-1;
      bool check(int n){//判断质数
      	for(int i=2;i*i<=n;i++){
      		if(n%i==0)return false;
      	}
      	return true;
      }
      int main(){
      	cin>>n;
      	for(int i=2;i<=n/2;i++){
      		int a=n-i;
      		if(check(i)&&check(a)&&i*a>maxx)maxx=i*a;
      	}
      	cout<<maxx;
      	return 0;
      }
      
      • -1
        @ 2022-5-1 20:22:41

        #include<bits/stdc++.h> using namespace std; bool check(int k){ int i; for(i=3;ii<=k;i++){ if(k%i==0){ return false; } } return true; } int main(){ int a=1,b,i,j,max=0,s; cin>>s; for(i=3;i<=s;i+=2){ b=s-i; a=1; if(check(b)&&check(i)){ a=bi; if(a>max){ max=a; } } } cout<<max; return 0; }//暴力枚举

        • 1

        信息

        ID
        974
        时间
        1000ms
        内存
        128MiB
        难度
        5
        标签
        递交数
        392
        已通过
        147
        上传者