TZinovieva

Prime Pairs JS

Nov 17th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function primePairs(input) {
  2.     let startFirstCouple = Number(input[0]);
  3.     let startSecondCouple = Number(input[1]);
  4.     let diffFirstCouple = Number(input[2]);
  5.     let diffSecondCouple = Number(input[3]);
  6.  
  7.     let endFirstCouple = startFirstCouple + diffFirstCouple;
  8.     let endSecondCouple = startSecondCouple + diffSecondCouple;
  9.  
  10.     for (let i = startFirstCouple; i <= endFirstCouple; i++) {
  11.         for (let j = startSecondCouple; j <= endSecondCouple; j++) {
  12.  
  13.         let isPrime1 = true;
  14.         let isPrime2 = true;
  15.  
  16.         for (k = 2; k < i; k++) {
  17.             if (i % k === 0) {
  18.                 isPrime1 = false;
  19.                 break;
  20.             }
  21.         }
  22.             for (let l = 2; l < j; l++) {
  23.                 if (j % l === 0) {
  24.                     isPrime2 = false;
  25.                     break;
  26.                 }
  27.             }
  28.             if (isPrime1 && isPrime2) {
  29.                 primeCouple = `${i}${j}`
  30.                 console.log(primeCouple);
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment