結果

問題 No.1747 Many Formulae 2
ユーザー SSRSSSRS
提出日時 2021-11-19 21:22:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 166,848 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 20:42:40
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  for (int i = 0; i < (1 << (N - 1)); i++){
    long long x = S[0] - '0';
    long long sum = 0;
    for (int j = 0; j < N - 1; j++){
      if ((i >> j & 1) == 1){
        sum += x;
        x = 0;
      }
      x = x * 10 + (S[j + 1] - '0');
    }
    sum += x;
    if (sum > 1){
      bool ok = true;
      for (long long j = 2; j * j <= sum; j++){
        if (sum % j == 0){
          ok = false;
        }
      }
      if (ok){
        ans++;
      }
    }
  }
  cout << ans << endl;
}
0