8 条题解

  • 2
    @ 2025-11-29 9:14:04
    #include<bits/stdc++.h>
    //老登布置的作业-。-
    using namespace std;
    int zs(int x){
    	if(x<2) return 0;
    	for(int i=2;i<x;i++){
    		if(x%i==0){
    			return 0;
    		}
    	}
    	return 1;
    }
    int main(){
    	int n;
    	int sum;
    	int maxx=-1;
    	cin>>n;
    	for(int i=1;i<=(n-1)/2;i++){
    		if(zs(i)&&zs(n-i)){
    			if(i*(n-i)>maxx)
    			{
    				maxx=i*(n-i);
    			}
    		}
    	}
    	cout<<maxx;
    	return 0;
    	
    }
    
    
    • 2
      @ 2025-11-17 17:37:35
      # include <bits/stdc++.h>
      using namespace std;
      bool Accepted(int n){
      	if(n<2)return 0;
      	if(n==2)return 1;
      	for(int i = 2;i*i<=n;i++)
      	    if(n%i==0)
      	        return 0;
      	return 1;
      } 
      int main(){
      	int n,maxx=-1;
      	cin>>n;
      	for(int i = 1;i<=n/2+1;i++)
      	{
      		if(Accepted(i)==1&&Accepted(n-i)==1&&i*(n-i)>max)
      		{
      			maxx=i*(n-i);
      		}
      		    
      	}
      		
      	cout<<maxx<<endl;
      	return 0;
      }
      
      • 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-11-23 23:10:08

          #include<bits/stdc++.h> using namespace std; int N=-1e9+10; bool AC(int x){ for(int i=2;i<x;i++) if(x%i0) return false; return true; } int main(){ int a; cin>>a; for(int i=1;i<=a;i++){ int j=a-i; if(!(AC(j))||!(AC(i))) continue; if(i+ja){ N=max(N,i*j); } } cout << N; 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
                  标签
                  递交数
                  576
                  已通过
                  217
                  上传者