結果

問題 No.1747 Many Formulae 2
ユーザー momoyuumomoyuu
提出日時 2023-11-18 05:28:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 105,248 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-11-18 05:28:51
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<cassert>
#include<set>
#include<queue>
using namespace std;
using ll = long long;


string s;
int ans;
void dfs(ll now,ll tmp,int ni){
    int n = s.size();
    if(ni==n){
        now += tmp;
        bool fn = false;
        if(now==1) fn = true;
        for(ll i = 2;i*i<=now;i++){
            if(now%i==0)fn = true;
        }
        if(!fn) ans++;
        return;
    }

    if(ni!=0){
        ll nxt = now + tmp;
        ll t = s[ni] - '0';
        dfs(nxt,t,ni+1);
    }
    tmp *= 10;
    tmp += s[ni] -'0';
    dfs(now,tmp,ni+1);
}



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin>>s;
    dfs(0,0,0);
    cout<<ans<<endl;

}

0