Advertisement
bacco

Fast Prime Checker

May 23rd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FastPrimeCheckerRefactor
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             for (int i = 2; i <= n; i++)
  11.             {
  12.                 bool isPrime = true;
  13.                 for (int divisor = 2; divisor <= Math.Sqrt(i); divisor++)
  14.                 {
  15.                     if (i % divisor == 0)
  16.                     {
  17.                         isPrime = false;
  18.                         break;
  19.                     }
  20.                 }
  21.                 Console.WriteLine($"{i} -> {isPrime}");
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement