Facebook
From Eryk Bartosik, 4 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 260
  1. using System;
  2. using System.Numerics;
  3. using System.Diagnostics;
  4.  
  5. namespace ProjektAlgorytmy2
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             BigInteger[] tablica = new BigInteger[] { 100913, 1009139, 10091401, 100914061, 1009140611,  10091406133, 100914061337, 1009140613399 }; //tablica z wyrazami
  12.  
  13.             for( int i = 0 ; i < tablica.Length ; i++ ) //pętla wykonująca funkcję IsPrime dla wszystkich wyrazów tablicy ,,tablica"
  14.             {
  15.                 IsPrime(tablica[i]);
  16.             }
  17.         }
  18.  
  19.         static bool IsPrime(BigInteger Num) //przykładowa funkcja z PDF
  20.         {
  21.             if (Num < 2) return false;
  22.             else if (Num < 4) return true;
  23.             else if (Num % 2 == 0) return false;
  24.             else for (BigInteger u = 3; u < Num / 2; u += 2)
  25.             if (Num % u == 0) return false;
  26.             return true;
  27.         }
  28.     }
  29. }
  30.