結果

問題 No.1747 Many Formulae 2
ユーザー bonKotsubonKotsu
提出日時 2022-07-23 20:32:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,149 bytes
コンパイル時間 4,395 ms
コンパイル使用メモリ 261,424 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 21:50:23
合計ジャッジ時間 5,437 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

bool isPrime(ll x) {
  for (int i = 2; i*i <= x; i++) {
    if (x%i==0) return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  rep(i,1<<(n-1)) {
    
    auto f = [&](string s, int bit) {
      vector<int> v;
      v.pb(0);
      rep(j,n) {
        if ((bit>>j)&1) v.pb(j+1);
      }
      v.pb(n);
      ll res = 0;
      rep(j, v.size()-1) {
        ll ten = 1;
        for (int k = v[j+1]-1; k >= v[j]; k--) {
          res += ten*(s[k]-'0');
          ten *= 10;
        }
      }
      
      return res;
    };
    
    ll x = f(s,i);
    if (isPrime(x)) ans++;
  }
  cout << ans << endl;

  return 0;
}
0