예제 #1
0
        public static PrimeSet GenerateInitialPrimeSet()
        {
            PrimeSet primes = new PrimeSet();
            int      dt     = (((DateTime.Now.Day * 24 + DateTime.Now.Hour) * 60 + DateTime.Now.Minute) * 60 + DateTime.Now.Second) * 1000 + DateTime.Now.Millisecond;

            primes.Primes = _firstPrimeSet = new List <long>();
            primes.Primes.Add(2);
            for (long j = 3; j <= SetNumberSpan; j++)
            {
                bool prime = true;
                for (int h = 0; _firstPrimeSet[h] * _firstPrimeSet[h] <= j; h++)
                {
                    if (j % _firstPrimeSet[h] == 0)
                    {
                        prime = false;
                        break;
                    }
                }
                if (prime)
                {
                    primes.Primes.Add(j);
                }
            }
            dt = (((DateTime.Now.Day * 24 + DateTime.Now.Hour) * 60 + DateTime.Now.Minute) * 60 + DateTime.Now.Second) * 1000 + DateTime.Now.Millisecond - dt;
            primes.TotalGenerationTime   = dt;
            primes.AverageGenerationTime = dt / primes.Primes.Count;
            return(primes);
        }
예제 #2
0
 public void CollectBlock(int block)
 {
     _thread = new System.Threading.Thread(() =>
     {
         Finished = false;
         //setting span for generation
         long start = SetNumberSpan * block, end = start + SetNumberSpan;
         //generating primes
         var primes = new PrimeSet();
         primes.AverageGenerationTime = (((DateTime.Now.Day * 24 + DateTime.Now.Hour) * 60 + DateTime.Now.Minute) * 60 + DateTime.Now.Second) * 1000 + DateTime.Now.Millisecond;
         primes.Primes = new List <long>();
         for (long j = start; j <= end; j++)
         {
             bool prime = true;
             for (int h = 0; _firstPrimeSet[h] * _firstPrimeSet[h] <= j; h++)
             {
                 if (j % _firstPrimeSet[h] == 0)
                 {
                     prime = false;
                     break;
                 }
             }
             if (prime)
             {
                 primes.Primes.Add(j);
             }
         }
         primes.AverageGenerationTime = (((DateTime.Now.Day * 24 + DateTime.Now.Hour) * 60 + DateTime.Now.Minute) * 60 + DateTime.Now.Second) * 1000 + DateTime.Now.Millisecond - primes.AverageGenerationTime;
         primes.TotalGenerationTime   = primes.AverageGenerationTime;
         primes.AverageGenerationTime = primes.AverageGenerationTime / primes.Primes.Count;
         Finished = true;
     });
     _thread.Start();
 }