private bool AreGcdEqual(int a, int b, int c) { var gcd1 = _totient.GreatestCommonDivisor(a, b); var gcd2 = _totient.GreatestCommonDivisor(a, c); var gcd3 = _totient.GreatestCommonDivisor(b, c); return(gcd1 == gcd2 && gcd2 == gcd3); }
public Tuple <int, int> GetPreviousNumberBefore3Over7(int upto) { double comparisonValue = (double)3 / 7; double previousValue = 0; Tuple <int, int> previousTuple = new Tuple <int, int>(0, 0); for (int n = 1; n < upto; n++) { for (int d = upto; d >= n + 1; d--) { double fractionValue = (double)n / d; if (fractionValue > comparisonValue) { break; } if (previousValue > fractionValue) { continue; } if (n % d == 0 || d % n == 0) { continue; } if ((n != 3 && d != 7) && _totient.GreatestCommonDivisor(n, d) == 1) { previousValue = fractionValue; previousTuple = new Tuple <int, int>(n, d); } } } return(previousTuple); }
public void TestGreatestCommonDivisorCollectionCreation() { const int upto = 100; Dictionary <Tuple <int, int>, int> lookup = new Dictionary <Tuple <int, int>, int>(); for (int i = 1; i <= upto; i++) { for (int j = 2; j <= upto; j++) { Tuple <int, int> key = new Tuple <int, int>(j, i); //if (!lookup.ContainsKey(key)) lookup[key] = _sut.GreatestCommonDivisor(j, i); } } _output.WriteLine(lookup.Keys.Count.ToString()); }