Advertisement
vaakata

PrimesCheck_20.05.2016

Jun 2nd, 2016
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 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 PrimeCheckSoftUni_20._05._2016
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long n = long.Parse(Console.ReadLine());
  14.             Console.WriteLine(IsPrime(n));
  15.         }
  16.  
  17.         static bool IsPrime(long n)
  18.         {
  19.             int sqrtN = (int)Math.Sqrt(n);
  20.             if (n <= 1)
  21.             {
  22.                 return false;
  23.             }
  24.             else if (n > 2)
  25.             {
  26.                 for (int cnt = 2; cnt <= sqrtN; cnt++)
  27.                 {
  28.                     if (n % cnt == 0)
  29.                     {
  30.                         return false;
  31.                     }                    
  32.                 }
  33.             }
  34.             return true;
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement