結果
| 問題 | 
                            No.1747 Many Formulae 2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-11-22 21:56:32 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 957 bytes | 
| コンパイル時間 | 2,666 ms | 
| コンパイル使用メモリ | 158,504 KB | 
| 最終ジャッジ日時 | 2025-01-26 00:26:07 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#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;
}