From 49673d472b1e89b04f56a367e521c514dd11f917 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 10 Jun 2022 16:48:16 +0800 Subject: [PATCH] =?UTF-8?q?4268.=20=E6=80=A7=E6=84=9F=E7=B4=A0=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/14678536/ --- AcWing/4268/4268.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ AcWing/4268/data/11.ans | 3 +++ AcWing/4268/data/11.in | 3 +++ AcWing/4268/data/12.ans | 3 +++ AcWing/4268/data/12.in | 3 +++ 5 files changed, 54 insertions(+) create mode 100644 AcWing/4268/4268.cpp create mode 100644 AcWing/4268/data/11.ans create mode 100644 AcWing/4268/data/11.in create mode 100644 AcWing/4268/data/12.ans create mode 100644 AcWing/4268/data/12.in diff --git a/AcWing/4268/4268.cpp b/AcWing/4268/4268.cpp new file mode 100644 index 00000000..466b311f --- /dev/null +++ b/AcWing/4268/4268.cpp @@ -0,0 +1,42 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +bool isPrime(int x) { + if (x <= 1) return false; + + for (int i = 2; i * i <= x; i++) { + if (x % i == 0) { + return false; + } + } + + return true; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int x; + + cin >> x; + + if (isPrime(x) && isPrime(x - 6)) { + cout << "Yes" << endl + << x - 6 << endl; + } else if (isPrime(x) && isPrime(x + 6)) { + cout << "Yes" << endl + << x + 6 << endl; + } else { + cout << "No" << endl; + + while (!(isPrime(x) && (isPrime(x - 6) || isPrime(x + 6)))) x++; + + cout << x << endl; + } + + return 0; +} diff --git a/AcWing/4268/data/11.ans b/AcWing/4268/data/11.ans new file mode 100644 index 00000000..0cd297f6 --- /dev/null +++ b/AcWing/4268/data/11.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:135e708807abf377262dd94af08aba7c7a1c6cdf74660d21df126ccdaac513b0 +size 12 diff --git a/AcWing/4268/data/11.in b/AcWing/4268/data/11.in new file mode 100644 index 00000000..7175446c --- /dev/null +++ b/AcWing/4268/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b8fa8aa834e3c92d735301304945c0a2dfc02b4d01d80fc0d0fd30c2f03f0c6 +size 9 diff --git a/AcWing/4268/data/12.ans b/AcWing/4268/data/12.ans new file mode 100644 index 00000000..e924079e --- /dev/null +++ b/AcWing/4268/data/12.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1785e4eba9acc6cb90751d58a37221f56353643c3b5144c81115932e09ab56c4 +size 5 diff --git a/AcWing/4268/data/12.in b/AcWing/4268/data/12.in new file mode 100644 index 00000000..1afab5f7 --- /dev/null +++ b/AcWing/4268/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865 +size 2