結果

問題 No.1747 Many Formulae 2
ユーザー warm4C0warm4C0
提出日時 2021-11-19 22:00:33
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 158,008 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-01 19:56:06
合計ジャッジ時間 2,015 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int solve(string s) {
    int n = s.size();

    int ans = 0;
    for (int i = 0; i < (1<<(n-1)); i++) {
        ll sum = 0;
        string t = "";
        for (int j = 0; j < n; j++) {
            if (j == n-1 || (i>>j)&1) {
                t += s[j];
                sum += stoll(t);
                t = "";
            } else {
                t += s[j];
            }
        }
        ans += is_prime(sum);
    }

    return ans;
}

int main() {
    string s;
    cin >> s;

    cout << solve(s) << endl;

    return 0;
}
0