結果

問題 No.1747 Many Formulae 2
ユーザー monaka
提出日時 2021-12-30 06:16:38
言語 TypeScript
(5.7.2)
結果
WA  
実行時間 -
コード長 516 bytes
コンパイル時間 8,164 ms
コンパイル使用メモリ 229,064 KB
実行使用メモリ 43,264 KB
最終ジャッジ日時 2024-12-31 16:42:02
合計ジャッジ時間 10,168 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

let count = 0;

function walk(str, sum) {
  for(let i=1; i<str.length; i++) {
    const l = str.substr(0, i);
    const r = str.substr(i);
    walk(r, Number(sum)+Number(l));
  }
  if(isPrime(Number(sum)+Number(str))) {
    count++;
  }
}

function isPrime(num) {
  if(num === 1) return false;
  for(let i=2; i*i<num; i++) {
    if(num % i === 0) return false;
  } 
  return true;
}

function main(str) {
  walk(str, 0);
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n")[0]);
0