結果
問題 | No.1747 Many Formulae 2 |
ユーザー |
![]() |
提出日時 | 2023-05-28 19:49:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 937 ms |
コンパイル使用メモリ | 104,524 KB |
最終ジャッジ日時 | 2025-02-13 15:50:53 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <complex> #include <cassert> using namespace std; using ll = long long; bool is_prime(long long N){ if (N == 0 || N == 1) return false; for (long long i=2; i*i<=N; i++){ if (N % i == 0) return false; } return true; } int main(){ string S; cin >> S; ll ans=0, sm, N=S.size(), s; for (int i=0; i<(1<<(N-1)); i++){ sm = 0; s = S[0]-'0'; for (int j=0; j<N-1; j++){ if (!(i & 1<<j)) s = s*10 + (S[j+1]-'0'); else{ sm += s; s = S[j+1]-'0'; } } sm += s; if (is_prime(sm)) ans++; } cout << ans << endl; return 0; }