From 8e2bd531b5669475555a18415893be85cf99a1a7 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 14 Apr 2021 10:54:12 -0500 Subject: Did you know trig functions can compute modulos! --- gcd/gcd.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 gcd/gcd.cpp (limited to 'gcd') 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 +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<