Advertisement
AlexTasev

Prime Pairs

Apr 23rd, 2018
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _6_PairPrimes
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int num1 = int.Parse(Console.ReadLine());
  10.             int num2= int.Parse(Console.ReadLine());
  11.  
  12.             int num1To = int.Parse(Console.ReadLine());
  13.             int num2To = int.Parse(Console.ReadLine());
  14.  
  15.             for (int n = num1; n <= num1 + num1To; n++)
  16.             {
  17.                 for (int m = num2; m <= num2 + num2To; m++)
  18.                 {
  19.                     bool isNPrime = true;
  20.                     bool isMPrime = true;
  21.  
  22.                     for (int i = 2; i <= Math.Sqrt(n); i++)
  23.                     {
  24.                         if (n % i == 0)
  25.                         {
  26.                             isNPrime = false;
  27.                             break;
  28.                         }
  29.                     }
  30.                     for (int j = 2; j <= Math.Sqrt(m); j++)
  31.                     {
  32.                         if (m % j == 0)
  33.                         {
  34.                             isMPrime = false;
  35.                             break;
  36.                         }
  37.                     }
  38.  
  39.                     if (isNPrime && isMPrime)
  40.                     {
  41.                         Console.WriteLine($"{n}{m}");
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement