結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
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;
  }
  cout << x << endl;
  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