webturing vor 5 Jahren
Ursprung
Commit
26b0a2fd30
1 geänderte Dateien mit 29 neuen und 0 gelöschten Zeilen
  1. 29 0
      C.cpp

+ 29 - 0
C.cpp

@@ -0,0 +1,29 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+bool prime(int n) {
+    if (n == 2)return true;
+    if (n % 2 == 0 || n < 2)return false;
+    for (int c = 3; c * c <= n; c += 2)
+        if (n % c == 0)return false;
+    return true;
+}
+
+int solve(int n) {
+    int tot = 0;
+    int p = n >> 1;
+    if (p % 2 == 0)--p;
+    for (; p >= 3; p -= 2)
+        if (prime(p) && prime(n - p)) {
+            ++tot;
+        }
+    return tot;
+}
+
+int main() {
+    for (int n; cin >> n;)
+        cout << solve(n) << endl;
+    return 0;
+}
+