Guest User

Prime Triangle

a guest
Sep 18th, 2020
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let n = +gets();
  2. let arrPrime = [];
  3.  
  4. for (let i = n; i > 1; i--) {
  5.     for (let j = 2; j < i; j++) {
  6.         if (i % j == 0) {
  7.             break;
  8.         }
  9.         if (j == i - 1) {
  10.             arrPrime.unshift(i);
  11.         }
  12.     }
  13. }
  14. arrPrime.unshift(1, 2);
  15.  
  16.  
  17. let count = arrPrime.length;
  18.  
  19. for (let i = 0; i < count; i++) {
  20.  
  21.     num = arrPrime[i];
  22.  
  23.     let colum = '';
  24.     for (let j = 1; j <= num; j++) {
  25.  
  26.         if (j == 1 || j == 2 || j == 3 || j == num) {
  27.             colum += 1;
  28.         } else {
  29.  
  30.             for (let k = 2; k <= j; k++) {
  31.                 if (j % k == 0 && j != k) {
  32.                     colum += 0;
  33.                     break;
  34.                 } else if (k == j) {
  35.                     colum += 1;
  36.                 }
  37.             }
  38.         }
  39.     }
  40.     print(colum);
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment