結果

問題 No.1747 Many Formulae 2
ユーザー naskya
提出日時 2021-11-20 02:43:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 67,072 KB
最終ジャッジ日時 2025-01-25 21:24:33
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

int main() {
  std::string S;
  std::cin >> S;

  const int N = static_cast<int>(std::size(S));
  int res     = 0;

  for (int mask = 0; mask < (1 << (N - 1)); ++mask) {
    long long value = 0, tmp = 0;

    for (int i = 0; i < N; ++i) {
      tmp = tmp * 10 + (S[i] - '0');
      if (((mask >> i) & 1) == 1) {
        value += tmp;
        tmp = 0;
      }
    }

    value += tmp;

    res += [&] {
      if (value == 1) {
        return false;
      }
      for (int p = 2; p <= value / p; ++p) {
        if (value % p == 0) {
          return false;
        }
      }
      return true;
    }();
  }

  std::cout << res << '\n';
}
0