Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 04 / Solutions / exercise06.cpp
diff options
context:
space:
mode:
1 files changed, 38 insertions, 0 deletions
-rw-r--r--Sem. 04/Solutions/exercise06.cpp38
diff --git a/Sem. 04/Solutions/exercise06.cpp b/Sem. 04/Solutions/exercise06.cpp
new file mode 100644
index 0000000..3ced4c3
--- /dev/null
+++ b/Sem. 04/Solutions/exercise06.cpp
@@ -0,0 +1,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);
+}