Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const [players, loniNumber] = gets().split(' ').map(Number);
  2. const playersNumbers = gets().split(' ').map(Number);
  3. const scores = [];
  4.  
  5. const equalDivisors = (x) => {
  6.     let score = 0;
  7.  
  8.     for (let i = 2; i <= loniNumber; i++) {
  9.         if (x !== 0 && x !== 1) {
  10.             if (x % i === 0 && loniNumber % i === 0) {
  11.                 score += 1;
  12.             }
  13.         }
  14.     }
  15.     return score;
  16. }
  17.  
  18. for (const num of playersNumbers) {
  19.     scores.push(equalDivisors(num))
  20. }
  21. const max = Math.max(...scores)
  22. const positions = [];
  23.  
  24. for (let i = 1; i <= playersNumbers.length; i++) {
  25.     if (equalDivisors(playersNumbers[i]) === max) {
  26.         positions.push(i + 1);
  27.     }
  28. }
  29. if (max) {
  30.     print(max);
  31.     print(positions.join(' '));
  32. } else {
  33.     print('No winners');
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement