結果
| 問題 |
No.1747 Many Formulae 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 14:14:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 4,313 ms |
| コンパイル使用メモリ | 252,728 KB |
| 最終ジャッジ日時 | 2025-02-21 06:34:39 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;
bool is_prime(ll x) {
if (x == 1) return false;
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
ll calc(string t) {
vector<ll> v;
string tmp;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '+') {
//cout << t << ' ' << tmp << endl;
v.push_back(stoll(tmp));
tmp = "";
} else {
tmp += t[i];
}
}
//cout << t << ' ' << tmp << endl;
v.push_back(stoll(tmp));
ll res = 0;
for (int i = 0; i < v.size(); i++) {
res += v[i];
}
return res;
}
int main() {
ll res = 0;
string s; cin >> s;
int n = s.size();
for (ll b = 0; b < (1LL << n - 1); b++) {
string t;
for (int i = 0; i < n; i++) {
t += s[i];
if (i < n - 1 && b >> i & 1) {
t += '+';
}
}
res += is_prime(calc(t));
}
cout << res << endl;
return 0;
}