Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is //in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace IsPrime
- {
- public class IsPrime
- {
- public static void Main()
- {
- Console.WriteLine("Въведи просто число");
- ulong n = ulong.Parse(Console.ReadLine());
- Console.WriteLine(isPrime(n));
- }
- public static bool isPrime(ulong n)
- {
- if(n <= 3)
- {
- return n > 1;
- }
- else if(n % 2 == 0 || n % 3 == 0)
- {
- return false;
- }
- for(ulong i = 5; i*i < n;i += 6)
- {
- if (n %i == 0 || n % (i+2) == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement