get prime number c#


 private int[] IsPrime(int upperLimit)  
     {  
       int sieveBound = (int)(upperLimit - 1) / 2;  
       int upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2;  
       BitArray PrimeBits = new BitArray(sieveBound + 1, true);  
       for (int i = 1; i <= upperSqrt; i++)  
       {  
         if (PrimeBits.Get(i))  
         {  
           for (int j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1)  
           {  
             PrimeBits.Set(j, false);  
           }  
         }  
       }  
       List<int> numbers = new List<int>((int)(upperLimit / (Math.Log(upperLimit) - 1.08366)));  
       numbers.Add(2);  
       for (int i = 1; i <= sieveBound; i++)  
       {  
         if (PrimeBits.Get(i))  
         {  
           numbers.Add(2 * i + 1);  
         }  
       }  
       return numbers.ToArray();  
     }  

Comments

Popular posts from this blog

Data Flow Diagram (DFD)

VERIFIKASI SUARA MENGGUNAKAN METODE MFCC DAN DTW MENGGUNAKAN METODE MFCC DAN DTW (BAB II TINJAUAN PUSTAKA)

flexigrid + php with add and edit button