-
-
Save maisterpl/c049d4b535bbae18928715e4ce93c435 to your computer and use it in GitHub Desktop.
liczby pierwsze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// program sprawdzajacy czy liczba jest liczba pierwsza | |
using System; | |
namespace liczby_pierwsze_spoj | |
{ | |
class Program | |
{ | |
static bool czypierwsza(int liczba) | |
{ | |
if (liczba == 2) return true; | |
else if (liczba % 2 == 0) return false; | |
for (int j = 3; j <= Math.Sqrt(liczba); j += 2) | |
{ | |
if (liczba % j == 0) | |
{ | |
return false; | |
} | |
} | |
return true; | |
} | |
static void Main() | |
{ | |
/* | |
for (int i = 9000; i < 10000; i++) | |
{ | |
Console.WriteLine("{0}, {1}", i, czypierwsza(i) ? "Tak" : "Nie"); | |
} | |
Console.WriteLine(czypierwsza(121) ? "Tak" : "Nie"); | |
Console.WriteLine(czypierwsza(169) ? "Tak" : "Nie"); | |
Console.WriteLine(czypierwsza(2) ? "Tak" : "Nie"); | |
*/ | |
int n; // liczba testow | |
n = Int32.Parse(Console.ReadLine()); | |
int[] tablica = new int[n]; | |
for (int i = 0; i < n; i++) | |
{ | |
tablica[i] = Int32.Parse(Console.ReadLine()); | |
} | |
foreach (int i in tablica) | |
{ | |
Console.WriteLine(czypierwsza(i) ? "Tak" : "Nie"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment