private BigInteger GetHigherPrime(BigInteger value) { if (value < Consts.BI2P64) { ulong ret = Prime53.GetHigherPrime(Common.ToULong(value)); if (ret != 0) { return(ret); } //value = Consts.BI2P64 - 1; value = Consts.BI2P64; // 2^64 is not prime } for (; ;) //while (value < Consts.BI2P4096_1) // 2^4096-1 is not prime { value++; if (PrimeUtils.IsPrime(value)) { return(value); } if (Ground.IsStopped()) { break; } } return(0); }
public static void FindPrimes(BigInteger minval, BigInteger maxval, string outFile) { FileTools.Delete(outFile); if (maxval < minval) { throw new Exception("maxval < minval"); } if (minval < Consts.BI2P64) { if (maxval < Consts.BI2P64) { Prime53.FindPrimes(Common.ToULong(minval), Common.ToULong(maxval), outFile, () => Ground.IsStopped() == false); } else { Prime53.FindPrimes(Common.ToULong(minval), ulong.MaxValue, outFile, () => Ground.IsStopped() == false); FindPrimes_BIBI(Consts.BI2P64, maxval, outFile, rate => 0.5 + rate * 0.5); } } else { FindPrimes_BIBI(minval, maxval, outFile, rate => rate); } }
public static BigInteger GetPrimeCount(BigInteger minval, BigInteger maxval) { BigInteger count; if (maxval < minval) { throw new Exception("maxval < minval"); } if (minval < Consts.BI2P64) { if (maxval < Consts.BI2P64) { count = Prime53.GetPrimeCount(Common.ToULong(minval), Common.ToULong(maxval), () => Ground.IsStopped() == false); } else { count = Prime53.GetPrimeCount(Common.ToULong(minval), ulong.MaxValue, () => Ground.IsStopped() == false); count += GetPrimeCount_BIBI(Consts.BI2P64, maxval, rate => 0.5 + rate * 0.5); } } else { count = GetPrimeCount_BIBI(minval, maxval, rate => rate); } return(count); }
public static bool IsPrime(BigInteger value) { if (value < Consts.BI2P64) { return(Prime53.IsPrime(Common.ToULong(value))); } return(IsPrime_M(value)); }
private BigInteger GetLowerPrime(BigInteger value) { while (Consts.BI2P64 <= value) { value--; if (PrimeUtils.IsPrime(value)) { return(value); } if (Ground.IsStopped()) { return(0); } } return(Prime53.GetLowerPrime(Common.ToULong(value))); }
private void Main2(ArgsReader ar) { using (new MSection(Ground.MtxProcStartEnd)) { Prime53.INIT(); Ground.LoadConf(); { string errorReportFile = Path.Combine(ProcMain.SelfDir, Consts.ERROR_REPORT_LOCAL_FILE); FileTools.Delete(errorReportFile); try { using (MSection.Unsection(Ground.MtxProcStartEnd)) { #if DEBUG // test code //new Test0001().Test01(); new Test0001().Test02(); //new Test0001().Test03(); //new Test0001().Test04(); //new Test0001().Test05(); //new Test0001().Test06(); //new Test0001().Test07(); #else this.Main3(ar); #endif } } catch (Exception e) { File.WriteAllText(errorReportFile, GetLiteMessage(e), Encoding.UTF8); throw; } } Common.RemoveReportFile(); } Ground.Destroy(); }