Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 03 / 04. Primes_In_Interval.cpp
blob: 6787e1f707af68247e6e4dacad469e4d1cc898f7 (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
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;

	if (a < 2) a = 2;

	for (int i = a; i <= b; i++)
	{
		bool isPrime = true;
		int rootOfI = sqrt(i);

		for (int j = 2; j <= rootOfI; j++)
		{
			if (i % j == 0)
			{
				isPrime = false;
				break;
			}
		}

		if (isPrime)
			cout << i << " ";
	}
	cout << endl;
}