Advertisement
YavorGrancharov

Prime_Number

Oct 5th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Prime_Number
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             long n = long.Parse(Console.ReadLine());
  10.             Console.WriteLine(isPrime(n));
  11.         }
  12.         public static bool isPrime(long n)
  13.         {
  14.             if (n == 0 || n == 1)
  15.             {
  16.                 return false;
  17.             }
  18.             if (n == 2)
  19.             {
  20.                 return true;
  21.             }
  22.  
  23.             var temp = Math.Floor(Math.Sqrt(n));
  24.             for (long i = 3; i <= temp; i+=2)
  25.             {
  26.                 if (n % i == 0)
  27.                 {
  28.                     return false;
  29.                 }
  30.             }
  31.             return true;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement