kirililchev3

Fast Prime Checker

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