結果

問題 No.882 約数倍数
ユーザー Takuya-AmpiTakuya-Ampi
提出日時 2020-03-12 11:07:36
言語 JavaScript
(node v21.7.1)
結果
WA  
実行時間 -
コード長 1,239 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 40,576 KB
最終ジャッジ日時 2024-04-21 03:13:25
合計ジャッジ時間 1,776 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
39,424 KB
testcase_01 AC 68 ms
39,424 KB
testcase_02 WA -
testcase_03 AC 71 ms
39,680 KB
testcase_04 AC 73 ms
39,808 KB
testcase_05 AC 69 ms
39,424 KB
testcase_06 AC 70 ms
39,552 KB
testcase_07 AC 68 ms
39,424 KB
testcase_08 AC 67 ms
39,552 KB
testcase_09 AC 67 ms
39,552 KB
testcase_10 AC 69 ms
39,680 KB
testcase_11 AC 67 ms
39,552 KB
testcase_12 AC 68 ms
39,424 KB
testcase_13 AC 69 ms
39,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
let lines = [];
reader.on("line", line => {
  lines.push(line);
});
reader.on("close", () => {
  const newArr = lines[0].split(' ').map(str => parseInt(str, 10))
  // 余り
  const remainder = newArr[0] % newArr[1]
  // 商
  const quotient = newArr[0] / newArr[1]
  // 素数(2以上の数で割って余りが0になることのない数(ただし、2を除く))判定。numが素数の時true,numが素数でない時falseで返す
  function primeNumber(num) {
    if (num === 2) {
      return true
    } else {
      for (let index = 2; index < num; index++) {
        if (num % index === 0) {
          return false;
          break
        }
        if (index + 1 === num) {
          return true
        }
      }
    }
  }
  // checkDivisorが1、または、checkRemainderが0かつcheckDivisorが素数でない時Yesと出力する
  switch (remainder) {
    case 0:
      if (quotient === 1) {
        console.log('YES')
      } else if (primeNumber(quotient)) {
        console.log('NO')
      } else {
        console.log('YES')
      }
      break;
    default:
      console.log('NO')
      break;
  }
});
0