結果

問題 No.1747 Many Formulae 2
ユーザー ぷらぷら
提出日時 2021-11-11 00:56:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 208,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 06:30:10
合計ジャッジ時間 3,126 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

struct primenumber {
    vector<int> spf;
    primenumber(int N) {
        init(N);
    }
    void init(int N) {
        spf.assign(N+1,0);
        for(int i = 0; i <= N; i++) {
            spf[i] = i;
        }
        for(int i = 2; i*i <= N; i++) {
            if(spf[i] == i) {
                for(int j = i*i; j <= N; j += i) {
                    if(spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    bool is_prime(long long n) {
        bool flag = true;
        if(n == 1) {
            flag = false;
        }
        for(long long i = 2; i*i <= n; i++) {
            if(n%i == 0) {
                flag = false;
            }
        }
        return flag;
    }
    map<int,int> get(int n) {
        map<int,int> m;
        while(n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    string S;
    cin >> S;
    int ans = 0;
    primenumber zz(1);
    for(int i = 0; i < (1 << S.size()); i++) {
        if(1 & i) {
            vector<int>tmp;
            for(int j = 0; j < S.size(); j++) {
                if(1 & (i >> j)) {
                    tmp.push_back(j);
                }
            }
            tmp.push_back(S.size());
            long long res = 0;
            for(int j = 1; j < tmp.size(); j++) {
                res += stoll(S.substr(tmp[j-1],tmp[j]-tmp[j-1]));
            }
            if(zz.is_prime(res)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}
0