aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2021-04-14 10:54:12 -0500
committerGitHub2021-04-14 10:54:12 -0500
commit8e2bd531b5669475555a18415893be85cf99a1a7 (patch)
tree6f67db5fe27be05610de17e0ccd69f0f193c8ac8
parent2a7ecbc90cfacdead423590447f0281f2f5a62f4 (diff)
Did you know trig functions can compute modulos!
-rw-r--r--gcd/gcd.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/gcd/gcd.cpp b/gcd/gcd.cpp
new file mode 100644
index 0000000..fb011bb
--- /dev/null
+++ b/gcd/gcd.cpp
@@ -0,0 +1,9 @@
+/*
+Problem: Find the greatest common divisor of two numbers.
+
+Solution: Euclidean algorithm except modulos are computed using trig functions!
+*/
+
+#include <bits/stdc++.h>
+int gcd(int a,int b){while(a^b)std::swap(b,a=b*(M_PI/2-atan(cos(M_PI*a/b)/sin(M_PI*a/b)))/M_PI+1e-9);return a;}
+int main(){std::cout<<gcd(126,84);}