Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Algorytm optymalny
- Int64 i, j, zakres, dokad;
- Int64[] tablica = new Int64[214748364];
- zakres = 2147424;
- dokad = (Int64)Math.Floor(Math.Sqrt(zakres));
- //inicjuj tablice
- for (i = 1; i <= zakres; i++) tablica[i] = i;
- //algorytm - sito eratostenesa
- for (i = 2; i <= dokad; i++)
- {
- if (tablica[i] != 0)
- {
- j = i + i;
- while (j <= zakres)
- {
- tablica[j] = 0;
- j += i;
- }
- }
- }
- for (int p = 0; p < mensuringPoint.Length; p++)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- long StartingTime1 = Stopwatch.GetTimestamp();
- Console.Write(IsPrimeX(mensuringPoint[p]));
- long EndingTime1 = Stopwatch.GetTimestamp();
- long ElapsedTime1 = EndingTime1 - StartingTime1;
- double ElapsedSeconds1 = ElapsedTime1 * (1.0 / Stopwatch.Frequency);
- Console.WriteLine(" Dla wartości: " + mensuringPoint[p]);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Ilośc dzielenia modulo: " + licz);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Czas wykonania: " + String.Format("{0:N7}", ElapsedSeconds1));
- Console.ResetColor();
- Console.WriteLine("-----------------------------------------");
- licz = 1;
- }
- bool IsPrimeX(Int64 Num)
- {
- if (Num < 2) return false;
- else if (Num < 4) return true;
- else if (Num % 2 == 0) return false;
- else for (int y = 3; tablica[y] < Math.Sqrt(Num); y += 2)
- {if (tablica[y] != 0)
- { licz++;
- if (Num % y == 0)
- {
- return false;
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement