結果

問題 No.1747 Many Formulae 2
ユーザー erbowlerbowl
提出日時 2022-08-18 22:02:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 196,464 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 05:29:54
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}

signed main(){
    string s;
    std::cin >> s;
    ll n = s.size();
    ll ans = 0;
    for (int i = 0; i < (1<<(n-1)); i++) {
        ll sum = 0;
        string now = s.substr(0,1);
        for (int j = 0; j < n-1; j++) {
            if(i>>j&1){
                sum += stoll(now);
                now = s.substr(j+1,1);
            }else{
                now += s.substr(j+1,1);
            }
        }
        sum += stoll(now);
        if(is_prime(sum)){
            ans++;
        }
    }
    std::cout << ans << std::endl;
}
0