VelizarAvramov

15. Fast Prime Checker

Nov 28th, 2019
138
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.  
  3. namespace _15._Fast_Prime_Checker
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int number = int.Parse(Console.ReadLine());
  10.  
  11.             for (int i = 2; i <= number; i++)
  12.             {
  13.                 bool isPrime = true;
  14.                 for (int k = 2; k <= Math.Sqrt(i); k++)
  15.                 {
  16.                     if (i % k == 0)
  17.                     {
  18.                         isPrime = false;
  19.                         break;
  20.                     }
  21.                 }
  22.                 Console.WriteLine($"{i} -> {isPrime}");
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment