Facebook
From Red Porcupine, 4 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 203
  1. using System;
  2. using System.Diagnostics;
  3. using System.Numerics;
  4.  
  5. namespace Projekt2
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             BigInteger[] liczba = new BigInteger[8] {100913,1009139, 10091401, 100914061, 1009140611,  10091406133, 100914061337, 1009140613399};
  12.             /*for(int i = 6; i < liczba.Length ; i++)
  13.             {
  14.             Stopwatch stoper = new Stopwatch();
  15.             stoper.Start();
  16.             IsPrime(liczba[i]);
  17.             stoper.Stop();
  18.             Console.WriteLine("CZAS: "+stoper.ElapsedMilliseconds);
  19.             stoper.Reset();
  20.             }*/
  21.             Console.WriteLine();
  22.             for(int i = 0; i < liczba.Length; i++)
  23.             {
  24.             IsPrime2(liczba[i]);
  25.             }
  26.         }
  27.  
  28.         static bool IsPrime(BigInteger Num)
  29.         {
  30.             if (Num < 2) return false;
  31.             else if (Num < 4) return true;
  32.             else if (Num % 2 == 0) return false;
  33.             else for (BigInteger u = 3; u < Num / 2; u += 2)
  34.                         if (Num % u == 0) return false;
  35.             return true;
  36.         }
  37.  
  38.         static bool IsPrime2(BigInteger Num)
  39.         {
  40.             if (Num < 2) return false;
  41.             else if (Num < 4) return true;
  42.             else if (Num % 2 == 0) return false;
  43.             else for (BigInteger u = 3; u*u <= Num; u += 2)
  44.                 if (Num % u == 0) return false;
  45.             return true;
  46.         }
  47.     }
  48. }
  49.