結果

問題 No.1747 Many Formulae 2
ユーザー horoyoisawahoroyoisawa
提出日時 2022-02-03 14:44:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 166,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 03:17:53
合計ジャッジ時間 2,598 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool prime(long long n) {
    bool ret = true;
    if(n == 1) ret = false;
    for(int i=2;i<sqrt(n) + 1;i++) {
        if(n % i == 0) {
            ret = false;
            break;
        }
    }

    return ret;
}

int main() {
    string s;
    cin >> s;
    int n = s.size() - 1;
    int out = 0;
    for(int i=0;i<(1<<n);i++) {
        bitset<9> b(i);
        int tmp = 0;
        long long total = 0;
        for(int j=0;j<n;j++) {
            if(b.test(j)) {
                string sub = s.substr(tmp, (j - tmp) + 1);

                tmp = j + 1;

                total += stoll(sub);
            } 
        }
        total += stoll(s.substr(tmp, (n - tmp) + 1));

        if(prime(total)) out++;
    }

    cout << out << endl;
}
0