From 382557a7c8be5066c336d7aec6b374d9c99d1ea5 Mon Sep 17 00:00:00 2001 From: Myun2 Date: Sat, 16 Oct 2010 00:32:46 +0900 Subject: [PATCH] =?utf8?q?math/gcd=5Flcm.hpp:=20gcd=5F()=E3=81=AE=E4=B8=AD?= =?utf8?q?=E8=BA=AB=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/math/gcd_lcm.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/roast/include/roast/math/gcd_lcm.hpp b/roast/include/roast/math/gcd_lcm.hpp index 1b4a63cf..d7d0b6c4 100644 --- a/roast/include/roast/math/gcd_lcm.hpp +++ b/roast/include/roast/math/gcd_lcm.hpp @@ -11,10 +11,22 @@ namespace roast template T gcd_(T a, T b) { + if ( a == 0 || b == 0 ) + return 0; + + while(1) + { + T r = a % b; + if ( r == 0 ) + return b; + a = b; + b = r; + } + //return 0; } int gcd(int a, int b){ return gcd_(a,b); } - + }//end of namespace roast #endif//__SFJP_ROAST__math__gcd_lcm_HPP__ -- 2.11.0