public static bool SatisfiesConjecture(long n, SortedSet <long> primes, SortedSet <long> twiceSquares) { while (primes.Max < n) { primes.Add(PrimeUtils.NextPrime(primes)); } while (twiceSquares.Max < n) { twiceSquares.Add(2 * (long)Math.Pow(twiceSquares.Count, 2)); } return(primes.Any(p => twiceSquares.Contains(n - p))); }
private void IncreaseBitSetCapacity(Int32 count) { Int32 size = PrimeUtils.NextPrime(count); if (size > _freeIdSize) { size = _freeIdSize; } BitSet newBitSet = new BitSet(size); newBitSet.Or(_freeIds); _freeIds = newBitSet; }
public Boolean Initialize() { try { _freeIds = new BitSet(PrimeUtils.NextPrime(100000)); _freeIds.Clear(); _freeIdCount = _freeIdSize; foreach (UInt32 usedObjectId in ExtractUsedObjectIdTable()) { if (_exclude.Contains(usedObjectId)) { continue; } Int32 objectId = (Int32)(usedObjectId - _firstId); if (usedObjectId < _firstId) { #if NLOG _log.Warn("{0}: Object ID {1} in DB is less than {2}", _name, usedObjectId, _firstId); #endif continue; } if (objectId >= _freeIds.Count) { IncreaseBitSetCapacity(objectId + 1); } _freeIds.Set(objectId); Interlocked.Decrement(ref _freeIdCount); } _nextFreeId = _freeIds.NextClear(0); #if NLOG _log.Info("{0} successfully initialized", _name); #endif } catch (Exception e) { #if NLOG _log.Error("{0} could not be initialized correctly", _name); _log.Error(e); #endif return(false); } return(true); }
public static IEnumerable <long[]> Main() { var primes = new SortedSet <long> { 2, 3, 5, 7 }; var primesTodo = new SortedSet <long>(); var digits = 2; while (true) { var maxForDigits = Math.Pow(10, digits); while (primes.Max < maxForDigits) { var nxt = PrimeUtils.NextPrime(primes); if (nxt >= maxForDigits) { break; } primes.Add(nxt); primesTodo.Add(nxt); } while (primesTodo.Any()) { var todo = primesTodo.First(); foreach (var family in Replacements(todo)) { var familyPrimes = family.Where(x => primes.Contains(x)).ToArray(); yield return(familyPrimes); primesTodo.ExceptWith(familyPrimes); } } digits++; } }
public static long Main(int distinctCount) { var primes = new List <long> { 2 }; var count = 0; var n = 2L; while (count != distinctCount) { if (primes.Last() < n) { primes.Add(PrimeUtils.NextPrime(primes)); } // stop collecting factors if more than distinct count var primeFactors = GetPrimeFactors(n, primes).TakeWhile((x, i) => i <= distinctCount); count = primeFactors.Count() == distinctCount ? count + 1 : 0; n++; } return(n - distinctCount); }