代码拉取完成,页面将自动刷新
/***
* Euclidean Algorithm to find the greatest common divisor of two numbers.
*
*/
namespace Algorithms.Numeric
{
public static class GreatestCommonDivisor
{
/// <summary>
/// Finds and returns the greatest common divisor of two numbers
/// </summary>
public static uint FindGCD(uint a, uint b)
{
if (a == 0)
return b;
if (b == 0)
return a;
uint _a = a, _b = b;
//Bitwise operator '&' works on individual bits of each value
//result is 0 or 1
//it works like a modulus operator '%' but is more efficient
uint r = _a & _b;
while(r != 0)
{
_a = _b;
_b = r;
r = _a & _b;
}
return _b;
}
/// <summary>
/// Determines given two numbers are relatively prime
/// </summary>
public static bool IsRelativelyPrime(uint a, uint b)
{
return FindGCD(a, b) == 1;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。