Esempio n. 1
0
        /// <summary>
        /// NOT IN USE, UNUSED
        ///
        /// CREATES LIST OF ALL PURE PRIME NUMBERS
        ///
        /// </summary>
        static void CreatePurePrimList()
        {
            long Max     = 1000000;
            long counter = 2;

            PrimeList.Add(new PureNumber(0, 0));

            long rank          = 0;
            int  prevPrimeRank = 0;

            while (counter < Max)
            {
                if (IsPrime(counter))
                {
                    rank = ++prevPrimeRank;//PrimeList.Count;
                    long newRank = rank;
                    while (rank != 1)
                    {
                        PureNumber ppO = PrimeList.Find(x => x.getValue() == rank);
                        if (null == ppO)
                        {
                            break;
                        }

                        rank = ppO.getIndex();
                    }
                    if (rank == 1 || PrimeList.Count <= 1)
                    {
                        PrimeList.Add(new PureNumber(prevPrimeRank, counter));
                        Console.WriteLine("{0}:{1}", prevPrimeRank, counter);
                    }
                }
                counter++;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// Using DYNAMIC PROGRAMING TO QUICKLY FIND THEIR SOLUTION OF ALREADY CALCULATED SOLUTION.
        ///
        /// </summary>
        /// <param name="tc"></param>
        /// <param name="outputPath"></param>
        static void SolveProblem(TestCase tc, string outputPath)
        {
            ls_TestCases = tc.lsTestCases;

            List <PureNumber> lsResults = new List <PureNumber>();

            int testcase_id = 0;

            foreach (int number in ls_TestCases)
            {
                countPure = 0;

                ++testcase_id;

                using (StreamWriter wr = new StreamWriter(outputPath, true))
                {
                    PureNumber objectfound = lsResults.Find(x => x.getIndex() == number);
                    if (objectfound == null)
                    {
                        CreateAllSubsetsCollection(number);

                        long mod = countPure % 100003;

                        wr.WriteLine("Case #{0}: {1}", testcase_id, mod);

                        lsResults.Add(new PureNumber(number, mod));

                        Console.WriteLine("\nCase #{0}: {1}", testcase_id, mod);
                    }
                    else
                    {
                        wr.WriteLine("Case #{0}: {1}", testcase_id, objectfound.getValue());

                        Console.WriteLine("Case #{0}: {1}", testcase_id, objectfound.getValue());
                    }
                }
            }


            return;
        }