From 2af7aac08e3bae3ed6e99fe04c32d39acb4bb129 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:34:38 +0200 Subject: Add files via upload --- Sem. 04/example01_no_functions.cpp | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Sem. 04/example01_no_functions.cpp (limited to 'Sem. 04/example01_no_functions.cpp') diff --git a/Sem. 04/example01_no_functions.cpp b/Sem. 04/example01_no_functions.cpp new file mode 100644 index 0000000..06e6629 --- /dev/null +++ b/Sem. 04/example01_no_functions.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i < n; i += 6) + { + int firstToCheck = i - 1; + int secondToCheck = i + 1; + + //prime check + bool isFirstPrime = true; + double temp = sqrt(firstToCheck); + for (int j = 2; j <= temp; j++) + { + if (firstToCheck % j == 0) + isFirstPrime = false; + } + + if (!isFirstPrime) + continue; + + //prime check + bool isSecondPrime = true; + double temp2 = sqrt(secondToCheck); + for (int j = 2; j <= temp2; j++) + { + if (secondToCheck % j == 0) + isSecondPrime = false; + } + + if (isSecondPrime) + cout << firstToCheck << " " << secondToCheck << endl; + } +} \ No newline at end of file -- cgit v1.3.1-23-gd82d