Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04 / example01_no_functions.cpp
blob: 06e662995a9ce43a3760f8c33b220cd648aa0cd9 (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
#include <iostream>
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;
	}
}