5 条题解

  • 1
    @ 2025-10-19 0:14:34

    质数的和与积

    AC代码

    #include<bits/stdc++.h>
    using namespace std;
    int n,maxx=-1e9;
    bool check(int a){
    	for(int i=2; i<a; i++)
    		if(a%i==0) return false;
    	return true;
    } 
    int main(){
    	cin >> n;
    	for(int i=1; i<=n; i++){
    		int j=n-i;
    		if(!(check(j))||!(check(i))) continue;
    		if(i+j==n){
    			maxx=max(maxx,i*j);
    		}		
    	}
    	cout << maxx;
    	return 0;
    }
    
    • -1
      @ 2025-3-9 15:19:46

      include <bits/stdc++.h>

      using namespace std; bool sushu(int num){ for(int i = 2;i*i<=num;i++){ if(num % i==0){ return false; } } return true; } int main(){ int n,max=0; cin>>n; for(int i = 2;i<=(n/2);i++) if(sushu(i) and sushu(n-i) and((n-i)*i >=max) ) max=(n-i)*i; cout<<max<<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
          @ 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;
          }
          
          • -4
            @ 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
            标签
            递交数
            569
            已通过
            215
            上传者