結果

問題 No.1747 Many Formulae 2
ユーザー warm4C0warm4C0
提出日時 2021-11-19 21:58:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 146,316 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 08:24:54
合計ジャッジ時間 3,194 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool is_prime(ll x) {
    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