Advertisement
simeon_petrov

34. Check Prime Number

Dec 3rd, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. public class CheckPrimeNumber
  5. {
  6.     static void Main()
  7.     {
  8.         BigInteger n = BigInteger.Parse(Console.ReadLine());
  9.         if (n < 2)
  10.         {
  11.             Console.WriteLine("Not Prime");
  12.             return;
  13.         }
  14.  
  15.         for (long i = 2; i < (long)Math.Floor(Math.Sqrt(double.Parse(n.ToString()))); i++)
  16.         {
  17.             if (n % i == 0)
  18.             {
  19.                 Console.WriteLine("Not Prime");
  20.                 return;
  21.             }
  22.         }
  23.  
  24.         Console.WriteLine("Prime");
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement