結果

問題 No.1747 Many Formulae 2
ユーザー hourenhouren
提出日時 2021-11-19 21:34:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 170,512 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 07:35:30
合計ジャッジ時間 2,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()

int main(){
    int MAX_N = 100100;
    vector<bool> PNJudge(MAX_N,true);
    vector<ll> pn;
    PNJudge[1] = false;
    for(int i=2;i<MAX_N;i++){
        if(!PNJudge[i]) continue;
        pn.push_back(i);
        for(int j=i*2;j<MAX_N;j+=i) PNJudge[j] = false;
    }
    string s;
    cin >> s;
    if(s=="1"){
        cout << 0 << endl;
        return 0;
    }
    int n = s.size(), ans = 0;
    rep(i,1<<(n-1)){
        int ic = i, be = 0;
        ll x = 0;
        rep(j,n-1){
            if(ic&1){
                x += stol(s.substr(be,j+1-be));
                be = j+1;
            }
            ic >>= 1;
        }
        x += stol(s.substr(be,n-be));
        bool ok = true;
        for(ll p:pn){
            if(!(x%p) && x/p != 1) ok = false;
        }
        ans += ok;
    }
    cout << ans << endl;
    return 0;
}
0