VelizarAvramov

15. Fast Prime Checker

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