Advertisement
AlexTasev

06_PrimeChecker

May 25th, 2018
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06_PrimeChecker
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             long inputNum = long.Parse(Console.ReadLine());
  10.             Console.WriteLine(IsPrime(inputNum));
  11.         }
  12.  
  13.         static bool IsPrime(long inputNum)
  14.         {
  15.             inputNum = Math.Abs(inputNum);
  16.             bool result = true;
  17.  
  18.             if (inputNum == 2)
  19.             {
  20.                 return true;
  21.             }
  22.             else if (inputNum == 1 || inputNum == 0)
  23.             {
  24.                 return false;
  25.             }
  26.  
  27.             for (int i = 2; i <= Math.Sqrt(inputNum); i++)
  28.             {
  29.                 if (inputNum % i == 0)
  30.                 {
  31.                     result = false;
  32.                     break;
  33.                 }
  34.             }
  35.             return result;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement