Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04 / Solutions / exercise06.cpp
blob: 3ced4c3b21b82dec5f62174f71ffa502f510a5ba (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
#include <iostream>
#include <cmath>

using namespace std;

bool isPowerOfSomething(int n)
{
	double rootOfN = sqrt(n);
	for (int i = 2; i <= rootOfN; i++)
	{
		if (n % i == 0)
		{
			while (n % i == 0)
				n /= i;

			return n == 1;
		}
	}
	return false; // Obligatory default case
}

void powerNumbersBetween(int a, int b)
{
	for (int i = a; i <= b; i++)
	{
		if (isPowerOfSomething(i))
			cout << i << " ";
	}
	cout << endl;
}

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

	powerNumbersBetween(a, b);
}