最大公约数

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

DECLARE @num1 BIGINT, 
        @num2 BIGINT 

SET @num1=14
SET @num2=21 

DECLARE @times INT 
DECLARE @min INT 
DECLARE @result BIGINT 

IF( @num1 >= @num2 ) 
  SET @min=@num2 
ELSE 
  SET @min=@num1 

SET @times=@min 

WHILE( @times <= @min ) 
  BEGIN 
      IF( @num1%@times = 0 
          AND @num2%@times = 0 ) 
        BEGIN 
            SET @result=@times 

            BREAK 
        END 

      SET @times=@times - 1 
  END 

SELECT @result