public void Add(CompositeFactor cf) { if (hashes.Add(cf.GetLongHashCode())) { items.Add(cf); } }
static void Main(string[] args) { var cfs = new CompositeFactors(); var cfHashes = new C5.HashSet <int>(); var b = ImmutableSortedDictionary.CreateBuilder <int, int>(); b.Add(0, Limit); CompositeFactor initial = new CompositeFactor(b); cfs.Add(initial); cfHashes.Add(initial.GetHashCode()); for (int i = 0; i < Limit - 1; i++) { if (i % 100 == 0) { Console.Write($"{(double)i / Limit:P1}, count = {cfs.Count} / {cfs.HashCount}\r"); } var firstUnexpanded = cfs.DeleteMin(); var expansions = firstUnexpanded.Expand(); foreach (var e in expansions) { cfs.Add(e); } cfs.Add(new CompositeFactor(firstUnexpanded.Factors.ToBuilder().Increase(0))); } Console.Out.WriteLine($"\nFound {Limit}th factor"); var answerFactor = cfs.DeleteMin(); mpz_t result = answerFactor.Factors.Aggregate(new mpz_t(1), (res, f) => res * new mpz_t(Primes.Values[f.Key]).Power(f.Value)).Mod(123454321); Console.WriteLine(result); }