QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210527 | #1932. Sum of Consecutive Prime Numbers | BoaHancock | 100 ✓ | 309ms | 3768kb | C++14 | 6.7kb | 2023-10-11 16:01:07 | 2023-10-11 16:01:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
class fastIO {
private:
char ibuf[50007], *p1 = ibuf, *p2 = ibuf, obuf[50007], *p3 = obuf, sta[50];
bool file_end = false;
char get() {
return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 50007, stdin), p1 == p2) ? (file_end = true), char(EOF): *p1++;
}
void put(const char x) {
p3 - obuf < 50007 ? *p3 ++ = x : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = x);
}
public:
explicit operator bool() { return !file_end; }
size_t flush() {
size_t f = fwrite(obuf, p3 - obuf, 1, stdout);
p3 = obuf;
*p3 = 0;
return f;
}
fastIO &operator>>(char &t) {
for (t = get(); !isgraph(t); t = get());
return *this;
}
template<typename any>
typename enable_if<is_same<any, char>::value, any>::type tpval() {
char t;
for (t = get(); !isgraph(t); t = get());
return t;
}
fastIO &operator>>(char *t) {
char c;
for (c = get(); !isgraph(c); c = get());
for (; isgraph(c); c = get())*t = c, t++;
*t = 0;
return *this;
}
fastIO &operator>>(string &t) {
t.clear();
char c;
for (c = get(); !isgraph(c); c = get());
for (; isgraph(c); c = get())t += c;
return *this;
}
template<typename any>
typename enable_if<is_same<any, string>::value, any>::type tpval() {
string t;
char c;
for (c = get(); !isgraph(c); c = get());
for (; isgraph(c); c = get())t += c;
return t;
}
template<typename any>
typename enable_if<
(is_signed<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
is_same<any, __int128_t>::value, fastIO>::type &operator>>(any &t) {
t = 0;
bool y = 0;
char c = get();
for (; !isdigit(c); c = get())if (c == 45)y = true;
for (; isdigit(c); c = get())t = t * 10 + c - 48;
if (y == 1)t = -t;
return *this;
}
template<typename any>
typename enable_if<
(is_signed<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
is_same<any, __int128_t>::value, any>::type tpval() {
any t = 0;
bool y = 0;
char c = get();
for (; !isdigit(c); c = get())if (c == 45)y = true;
for (; isdigit(c); c = get())t = t * 10 + c - 48;
if (y == 1)t = -t;
return t;
}
template<typename any>
typename enable_if<
(is_unsigned<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
is_same<any, __uint128_t>::value, fastIO>::type &operator>>(any &t) {
t = 0;
char c = get();
for (; !isdigit(c); c = get());
for (; isdigit(c); c = get())t = t * 10 + c - 48;
return *this;
}
template<typename any>
typename enable_if<
(is_unsigned<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
is_same<any, __uint128_t>::value, any>::type tpval() {
any t = 0;
char c = get();
for (; !isdigit(c); c = get());
for (; isdigit(c); c = get())t = t * 10 + c - 48;
return t;
}
template<typename any1, typename any2>
fastIO &operator>>(pair<any1, any2> &t) { return *this >> t.first >> t.second; }
template<typename any1, typename any2>
pair<any1, any2> tpval() { return pair<any1, any2>(tpval<any1>(), tpval<any2>()); }
template<typename any>
fastIO &read(any &t) { return *this >> t; }
fastIO &read(char *t) {
char c;
for (c = get(); !isgraph(c); c = get());
for (; isgraph(c); c = get())*t = c, t++;
*t = 0;
return *this;
}
template<typename any, typename...args>
fastIO &read(any &t1, args &...t2) { return (*this >> t1).read(t2...); }
fastIO &operator<<(const char t) {
put(t);
return *this;
}
fastIO &operator<<(const char *t) {
for (; *t; t++)put(*t);
return *this;
}
fastIO &operator<<(const string &t) {
for (const char it: t)put(it);
return *this;
}
template<typename any>
typename enable_if<
(is_signed<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
is_same<any, __int128_t>::value, fastIO>::type &operator<<(any t) {
if (!t) {
put(48);
return *this;
}
int len = 0;
if (t < 0)t = -t, put(45);
while (t)sta[len++] = char(t % 10 + 48), t /= 10;
while (len--)put(sta[len]);
return *this;
}
template<typename any>
typename enable_if<
(is_unsigned<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
is_same<any, __uint128_t>::value, fastIO>::type &operator<<(any t) {
if (!t) {
put(48);
return *this;
}
int len = 0;
while (t)sta[len++] = char(t % 10 + 48), t /= 10;
while (len--)put(sta[len]);
return *this;
}
template<typename any1, typename any2>
fastIO &operator<<(const pair<any1, any2> &t) { return *this << t.first << ' ' << t.second; }
template<typename any>
fastIO &write(const any &t) { return *this << t; }
template<typename any, typename...args>
fastIO &write(const any &t1, const args &...t2) { return (*this << t1).write(t2...); }
~fastIO() { fwrite(obuf, p3 - obuf, 1, stdout); }
}FastIO;
#define cin FastIO
#define cout FastIO
const int N = 1e4 + 5;
int primes[N], cnt, low[N];
bool st[N];
int sum[N];
inline void get_primes() {
st[0] = st[1] = true;
for(int i = 2; i < N; ++ i) {
if(!st[i]) primes[++ cnt] = i, low[i] = i;
for(int t = 1; primes[t] * i < N; ++ t) {
st[primes[t] * i] = true;
low[primes[t] * i] = primes[t];
if(i % primes[t] == 0) {
break;
}
}
}
}
void solve() {
int n;
while(cin >> n) {
if(n == 0) break;
int res = 0;
for(int i = 1; i <= n; ++ i) {
int now = 0;
for(int t = i; t <= n; ++ t) {
if(now >= n) break;
now += primes[t];
}
if(now == n) ++ res;
}
cout << res << '\n';
}
}
int32_t main() {
#ifdef ONLINE_JUDGE
#else
freopen("FuDiWeiU.in", "r", stdin);
freopen("FuDiWeiU.out", "w", stdout);
#endif
get_primes();
int T = 1;
// cin >> T;
while(T --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 309ms
memory: 3768kb
input:
3 17 41 666 1151 3264 2 5100 5999 311 6504 7451 7901 8819 863 9999 10000 7053 2914 827 302 12 3631 785 230 8011 1567 3198 2350 5307 3339 8929 9216 6479 4703 699 90 440 3926 1032 3329 3682 5764 1615 7961 53 9273 1275 4038 4923 540 7443 7837 1368 7746 1469 8505 4328 9480 6424 6678 1139 9763 1959 6707 ...
output:
1 2 3 0 4 4 1 4 4 5 4 4 4 4 5 1 0 0 2 2 0 1 2 0 0 2 1 4 1 0 0 1 0 1 1 0 2 1 0 2 2 0 1 0 1 2 0 0 1 0 2 0 0 0 0 0 1 1 0 1 1 2 0 1 1 0 0 0 1 0 1 0 0 4 1 0 2 4 0 0 0 1 0 0 0 1 1 0 3 0 0 4 4 0 1 1 0 0 0 4
result:
ok 100 lines