summaryrefslogtreecommitdiffstats
path: root/01-algorithmic_toolbox/01-intro/03-gcd
diff options
context:
space:
mode:
Diffstat (limited to '01-algorithmic_toolbox/01-intro/03-gcd')
-rw-r--r--01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp21
-rw-r--r--01-algorithmic_toolbox/01-intro/03-gcd/tests/011
-rw-r--r--01-algorithmic_toolbox/01-intro/03-gcd/tests/01.a1
-rw-r--r--01-algorithmic_toolbox/01-intro/03-gcd/tests/021
-rw-r--r--01-algorithmic_toolbox/01-intro/03-gcd/tests/02.a1
5 files changed, 25 insertions, 0 deletions
diff --git a/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp b/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp
new file mode 100644
index 0000000..f723be2
--- /dev/null
+++ b/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+int gcd(int a, int b) {
+ //write your code here
+ int current_gcd = 1;
+ for (int d = 2; d <= a && d <= b; d++) {
+ if (a % d == 0 && b % d == 0) {
+ if (d > current_gcd) {
+ current_gcd = d;
+ }
+ }
+ }
+ return current_gcd;
+}
+
+int main() {
+ int a, b;
+ std::cin >> a >> b;
+ std::cout << gcd(a, b) << std::endl;
+ return 0;
+}
diff --git a/01-algorithmic_toolbox/01-intro/03-gcd/tests/01 b/01-algorithmic_toolbox/01-intro/03-gcd/tests/01
new file mode 100644
index 0000000..46ce05e
--- /dev/null
+++ b/01-algorithmic_toolbox/01-intro/03-gcd/tests/01
@@ -0,0 +1 @@
+18 35
diff --git a/01-algorithmic_toolbox/01-intro/03-gcd/tests/01.a b/01-algorithmic_toolbox/01-intro/03-gcd/tests/01.a
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/01-algorithmic_toolbox/01-intro/03-gcd/tests/01.a
@@ -0,0 +1 @@
+1
diff --git a/01-algorithmic_toolbox/01-intro/03-gcd/tests/02 b/01-algorithmic_toolbox/01-intro/03-gcd/tests/02
new file mode 100644
index 0000000..4154bdb
--- /dev/null
+++ b/01-algorithmic_toolbox/01-intro/03-gcd/tests/02
@@ -0,0 +1 @@
+28851538 1183019
diff --git a/01-algorithmic_toolbox/01-intro/03-gcd/tests/02.a b/01-algorithmic_toolbox/01-intro/03-gcd/tests/02.a
new file mode 100644
index 0000000..855d3af
--- /dev/null
+++ b/01-algorithmic_toolbox/01-intro/03-gcd/tests/02.a
@@ -0,0 +1 @@
+17657