【问题标题】:Function to get Greatest common divisor between two number in Angular [duplicate]获取Angular中两个数字之间的最大公约数的函数[重复]
【发布时间】:2021-02-05 14:01:48
【问题描述】:

我需要一个计算两个数之间最大公约数的函数,数学库中有没有现成的函数或者我应该自己做如何计算?

谢谢

【问题讨论】:

标签: javascript angular function gdc


【解决方案1】:
function gcd_two_numbers(x, y) {
  if ((typeof x !== 'number') || (typeof y !== 'number')) 
    return false;
  x = Math.abs(x);
  y = Math.abs(y);
  while(y) {
    var t = y;
    y = x % y;
    x = t;
  }
  return x;
}

【讨论】:

    猜你喜欢
    • 2020-04-17
    • 2020-12-07
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 2022-11-27
    • 1970-01-01
    相关资源
    最近更新 更多