Advertisement
radidim

isPrime (C# Shell App Paste)

Aug 16th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is //in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace IsPrime
  8. {
  9.  
  10.     public class IsPrime
  11.     {
  12.         public static void Main()
  13.         {
  14.             Console.WriteLine("Въведи просто число");
  15.             ulong n = ulong.Parse(Console.ReadLine());
  16.             Console.WriteLine(isPrime(n));
  17.         }
  18.        
  19.         public static  bool isPrime(ulong n)
  20.         {
  21.             if(n <= 3)
  22.             {
  23.                 return n > 1;
  24.             }
  25.             else if(n % 2 == 0 || n % 3 == 0)
  26.             {
  27.                 return false;
  28.             }
  29.            
  30.             for(ulong i = 5; i*i < n;i += 6)
  31.             {
  32.                 if (n %i == 0 || n % (i+2) == 0)
  33.                 {
  34.                     return false;
  35.                 }
  36.             }
  37.             return true;
  38.            
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement