Advertisement
Guest User

06. Prime Checker

a guest
Oct 8th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.PrimeChecker
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long a = long.Parse(Console.ReadLine());
  14.  
  15.             if (IsPrime(a))
  16.             {
  17.                 Console.WriteLine("True");
  18.             }
  19.  
  20.             else
  21.             {
  22.                 Console.WriteLine("False");
  23.             }
  24.         }
  25.  
  26.         static bool IsPrime(long a)
  27.         {
  28.             if (a == 0 || a == 1)
  29.             {
  30.                 return false;
  31.             }
  32.  
  33.             for (int i = 2; i <= a/2; i++)
  34.             {
  35.                 if(a%i==0)
  36.                 return false;
  37.             }
  38.  
  39.             return true;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement