Advertisement
Sim0o0na

6. Prime Pairs

Mar 12th, 2018
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06_Sixth
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int firstpair = int.Parse(Console.ReadLine());
  14.             int secondpair = int.Parse(Console.ReadLine());
  15.             int firstpairLimit = int.Parse(Console.ReadLine());
  16.             int secodpairLimit = int.Parse(Console.ReadLine());
  17.  
  18.             for (int first = firstpair; first <= firstpair + firstpairLimit; first++)
  19.             {
  20.                 for (int second = secondpair; second <= secondpair + secodpairLimit; second++)
  21.                 {
  22.                     double squareRoot1 = (int)Math.Floor(Math.Sqrt(first));
  23.                     double squareRoot2 = (int)Math.Floor(Math.Sqrt(second));
  24.  
  25.                     bool isPrime1 = true;
  26.                     bool isPrime2 = true;
  27.                     if (first < 2)
  28.                     {
  29.                         isPrime1 = false;
  30.                     }
  31.                     if (second < 2)
  32.                     {
  33.                         isPrime2 = false;
  34.                     }
  35.  
  36.                     for (int i = 2; i <= squareRoot1; i++)
  37.                     {
  38.                         if (first % i == 0)
  39.                         {
  40.                             isPrime1 = false;
  41.                             break;
  42.                         }
  43.  
  44.                     }
  45.  
  46.  
  47.                     for (int i = 2; i <= squareRoot2; i++)
  48.                     {
  49.                         if (second % i == 0)
  50.                         {
  51.                             isPrime2 = false;
  52.                             break;
  53.                         }
  54.  
  55.                     }
  56.  
  57.                     if (isPrime1 == true && isPrime2 == true)
  58.                     {
  59.                         Console.Write(first);
  60.                         Console.WriteLine(second);
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement