5 条题解
-
1
包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
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
筛完质数就差不多做完了
#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
#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
- 上传者