2 条题解

  • 3
    @ 2026-3-28 16:10:58

    #include <bits/stdc++.h> using namespace std; int S; int ma;

    bool check(int n) { if (n < 2) return false; for (int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; }

    int main() { cin >> S; for (int i = 1; i <= S; ++i) if (check(i)) if (check(S - i)) if (i * (S - i) > ma) ma = i * (S - i); cout << ma; return 0; }

    • 0
      @ 2026-3-28 16:04:30

      #include <bits/stdc++.h>

      using namespace std;

      bool isPrime(int num) { if (num < 2) return false; for (int i = 2; i <= sqrt(num); i++) { if (num % i == 0) return false; } return true; }

      int main() { int S; cin >> S; int maxProduct = 0; for (int i = 2; i <= S / 2; i++) { if (isPrime(i) && isPrime(S - i)) { maxProduct = max(maxProduct, i * (S - i)); } } cout << maxProduct << endl; return 0; }

      • 1

      信息

      ID
      12095
      时间
      1000ms
      内存
      128MiB
      难度
      1
      标签
      递交数
      9
      已通过
      8
      上传者