Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise14.cpp
diff options
context:
space:
mode:
1 files changed, 26 insertions, 0 deletions
-rw-r--r--Week13/Exercise14.cpp26
diff --git a/Week13/Exercise14.cpp b/Week13/Exercise14.cpp
new file mode 100644
index 0000000..5a7f5dd
--- /dev/null
+++ b/Week13/Exercise14.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+
+const unsigned LEHMER_a = 16807;
+const unsigned LEHMER_m = ((unsigned long)1 << 31) - 1;
+
+void lehmerPrint(unsigned i, unsigned N, unsigned Xk) {
+ if (i >= N) {
+ std::cout << Xk << std::endl;
+ return;
+ }
+
+ if (i > 0)
+ std::cout << Xk << ' ';
+
+ lehmerPrint(i + 1, N, (LEHMER_a * Xk) % LEHMER_m);
+}
+
+int main()
+{
+ unsigned seed, N;
+ std::cin >> seed >> N;
+
+ lehmerPrint(0, N, seed);
+
+ return 0;
+}