結果

問題 No.1747 Many Formulae 2
ユーザー monaka
提出日時 2021-12-29 14:41:54
言語 TypeScript
(5.7.2)
結果
WA  
実行時間 -
コード長 486 bytes
コンパイル時間 8,157 ms
コンパイル使用メモリ 228,240 KB
実行使用メモリ 43,264 KB
最終ジャッジ日時 2024-12-31 16:41:51
合計ジャッジ時間 11,810 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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) {
  for(let i=2; 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