Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        private void Main3(ArgsReader ar)
        {
            Console.WriteLine("Prime4096_MillerRabin_K: " + Ground.MillerRabin_K);             // test

            if (ar.ArgIs("/S"))
            {
                Ground.Stop();
                return;
            }
            if (ar.ArgIs("/P"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("IsPrime_sn: " + sn);

                File.WriteAllText(outFile, PrimeUtils.IsPrime(Common.ToBigInteger(sn)) ? "P" : "N", Encoding.ASCII);
                return;
            }
            if (ar.ArgIs("/F"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("Factorization_sn: " + sn);

                FactorizationUtils.Factorization(Common.ToBigInteger(sn), outFile);
                return;
            }
            if (ar.ArgIs("/L"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("GetLowerPrime_sn: " + sn);

                File.WriteAllText(outFile, Common.ToString(
                                      GetLowerPrime(
                                          Common.ToBigInteger(sn)
                                          )
                                      ),
                                  Encoding.ASCII
                                  );
                return;
            }
            if (ar.ArgIs("/H"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("GetHigherPrime_sn: " + sn);

                File.WriteAllText(outFile, Common.ToString(
                                      GetHigherPrime(
                                          Common.ToBigInteger(sn)
                                          )
                                      ),
                                  Encoding.ASCII
                                  );
                return;
            }
            if (ar.ArgIs("/R"))
            {
                string sn1     = ar.NextArg();
                string sn2     = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("FindPrimes_sn1: " + sn1);
                Console.WriteLine("FindPrimes_sn2: " + sn2);

                FindPrimesUtils.FindPrimes(
                    Common.ToBigInteger(sn1),
                    Common.ToBigInteger(sn2),
                    outFile
                    );
                return;
            }
            if (ar.ArgIs("/C"))
            {
                string sn1     = ar.NextArg();
                string sn2     = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("GetPrimeCount_sn1: " + sn1);
                Console.WriteLine("GetPrimeCount_sn2: " + sn2);

                File.WriteAllText(outFile, Common.ToString(
                                      FindPrimesUtils.GetPrimeCount(
                                          Common.ToBigInteger(sn1),
                                          Common.ToBigInteger(sn2)
                                          )
                                      ),
                                  Encoding.ASCII
                                  );
                return;
            }
            throw new ArgumentException("不明なコマンド引数");
        }
Exemplo n.º 3
0
        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);
        }