public void Constructor_Init_Test() { var zero_natural = new Natural(0); var default_natural = new Natural(); var valid_natural = new Natural(Int32.MaxValue); Assert.AreEqual(zero_natural.GetIntValue(), default_natural.GetIntValue()); Assert.IsNotNull(default_natural.GetIntValue()); Assert.AreNotSame(zero_natural.GetIntValue(), valid_natural.GetIntValue()); Assert.AreEqual(zero_natural.GetIntValue(), valid_natural.GetIntValue() - valid_natural.GetIntValue()); Console.WriteLine("The value of zero initialization is: " + zero_natural.GetIntValue()); Console.WriteLine("The value of default initialization is: " + default_natural.GetIntValue()); Console.WriteLine("The value of a valid initialization is: " + valid_natural.GetIntValue()); }
public static bool DecreaseAndConquer(int limit, List <int> numbers) { //Natural number = new Natural(); //Natural gcd; //int relativelyprime = 1; List <Natural> list = new List <Natural>(); List <bool> pairwise = new List <bool>(); var pairs = new Dictionary <int, List <int> >(); foreach (var n in numbers) { list.Add(new Natural(n)); } for (int i = 0; i <= limit - 1; i++) { var current = new Natural(list[i].GetIntValue()); for (int j = 0; j <= limit - 1; j++) { if ((j == i) && (j != limit - 1)) { j++; } else if (i == limit - 1 && j == limit - 1) { continue; } if (pairs.ContainsKey(list[i].GetIntValue())) { pairs[list[i].GetIntValue()].Add(list[j].GetIntValue()); } else { pairs.Add(list[i].GetIntValue(), new List <int> { list[j].GetIntValue() }); } if (pairs.ContainsKey(list[j].GetIntValue())) { if (pairs[list[j].GetIntValue()].Contains(list[i].GetIntValue())) { continue; } } var sub = new Natural(current.GetIntValue()); //Console.WriteLine("DOING: " + sub.GetIntValue() + " GCD ON " + list[j].GetIntValue()); var subprogram = sub.Gcd(list[j]); //Console.WriteLine("EQUAL TO: " + subprogram.GetIntValue()); //GCD({0},{1}) = {3} if (subprogram.GetIntValue() == 1) { pairwise.Add(true); } else { pairwise.Add(false); } Console.WriteLine("GCD(" + list[i].GetIntValue() + "," + list[j].GetIntValue() + ") = " + subprogram.GetIntValue()); } } bool PairwiseRelativelyPrime; if (pairwise.Contains(false)) { PairwiseRelativelyPrime = false; } else { PairwiseRelativelyPrime = true; } return(PairwiseRelativelyPrime); }