結果

問題 No.1747 Many Formulae 2
ユーザー zezerozezero
提出日時 2021-11-22 21:56:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 3,070 ms
コンパイル使用メモリ 157,320 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 16:43:13
合計ジャッジ時間 4,227 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

int main(){
  string s;
  cin >> s;
  int ans = 0;                        
  int n = s.size()-1;
  for (int bit = 0; bit < (1 << n);bit++){
    ll res = 0;
    int pos = 0;
    int len = 1;
    for (int i = 0; i < n;i++){
      if (bit & 1 << i){
        res += stoll(s.substr(pos,len));
        len = 1;
        pos = i+1;
      }
      else len++;
    }
    res += stoll(s.substr(pos,n+1));
    bool isprime = true;
    for (ll i = 2; i*i <= res;i++){
      if (res%i == 0) {
        isprime = false;
        break;
      }
    }
    if (res == 1) isprime = false;
    if (isprime) ans++;
  }
  cout << ans << endl;
  
  return 0;
}
0