Advertisement
fbinnzhivko

prime

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