結果
| 問題 | 
                            No.1747 Many Formulae 2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             MasKoaTS
                         | 
                    
| 提出日時 | 2021-11-20 16:49:55 | 
| 言語 | C++17(gcc12)  (gcc 12.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 1,329 bytes | 
| コンパイル時間 | 17,871 ms | 
| コンパイル使用メモリ | 318,124 KB | 
| 最終ジャッジ日時 | 2025-01-25 21:58:48 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge10 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define lb lower_bound;
#define ub upper_bound;
//#define lb(A, x) (ll)(lower_bound(all(A), x) - A.begin())
//#define ub(A, x) (ll)(upper_bound(all(A), x) - A.begin())
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
template <class T>
const ll INF = 1000000000000000001;
const int inf = 1001001001;
const ll mod = 1000000007;
const ll MOD = 998244353;
bool isPrime(ll n) {
	if (n == 1) {
		return false;
	}
	for (int i = 2; (ll)i * (ll)i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}
void dfs(ll& ans, V<int>& vec, ll a, ll b, int k) {
	if (k == vec.size()) {
		if (isPrime(a + b)) {
			ans++;
		}
		return;
	}
	dfs(ans, vec, a, b * 10 + (ll)vec[k], k + 1);
	if (b > 0) {
		dfs(ans, vec, a + b, (ll)vec[k], k + 1);
	}
}
int main(void) {
	string s;	cin >> s;
	V<int> vec = {};
	for (auto& e : s) {
		vec.push_back(e - '0');
	}
	ll ans = 0;
	dfs(ans, vec, 0, 0, 0);
	cout << ans << endl;
	return 0;
}
            
            
            
        
            
MasKoaTS