Ton*_*nyK 11
吉姆·克莱(Jim Clay)的不谨慎评论激励他们采取行动,以下是欧几里德的六行代码算法:
bool RelativelyPrime (int a, int b) { // Assumes a, b > 0
  for ( ; ; ) {
    if (!(a %= b)) return b == 1 ;
    if (!(b %= a)) return a == 1 ;
  }
}
更新以添加:我已经被Omnifarious的这个答案混淆了,Omnifarious负责编程这个gcd函数:
constexpr unsigned int gcd(unsigned int const a, unsigned int const b)
{
   return (a < b) ? gcd(b, a) : ((a % b == 0) ? b : gcd(b, a % b));
}
所以现在我们有了一个三线版的RelativelyPrime:
bool RelativelyPrime (int a, int b) { // Assumes a, b > 0
   return (a<b) ? RelativelyPrime(b,a) : !(a%b) ? (b==1) : RelativelyPrime (b, a%b);
}