Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 6 / Task_1(without functions).cpp
blob: 9e5bcdbb6c147d75a1192cfcc1464dfa4475179c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;

	for (int i = 6; i <= n; i+=6)
	{
		int firstNumToCheck = i - 1, secondNumToCheck = i + 1;

		double temp = sqrt(firstNumToCheck);
		bool isFirstNumPrime = true;
		for (int j = 2; j <= temp; j++)
		{
			if (firstNumToCheck % j == 0)
			{
				isFirstNumPrime = false;
				break;
			}
		}

		if (!isFirstNumPrime)
			continue;
		double temp2 = sqrt(secondNumToCheck);
		bool isSecondNumPrime = true;
		for (int j = 2; j <= temp2; j++)
		{
			if (secondNumToCheck % j == 0)
			{
				isSecondNumPrime = false;
				break;
			}
		}
		if (isSecondNumPrime)
			cout << firstNumToCheck << " " << secondNumToCheck << endl;
	}

}