标签:mes space return cout 知识 out lock 奇迹 mat
求满足“日”组成的两位数,“月+日”组成的四位数,“年+月+日”组成的八位数均为质数的日期的个数。
略...
只要保证正确性且不会超时得太过分都能 AC
别问我部分分有啥用,我也不知道
两个易错点:
#include <bits/stdc++.h>
using namespace std;
const int p[] = {0,3,5,7,11,13,17,19,23,29,31,37};
const int d[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int T, a[66], t, ans[66666], tot;
char s[10];
inline bool is_prime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return 0;
return 1;
}
int main() {
ios::sync_with_stdio(0);
for (int i = 1; i <= 12; i++)
for (int j = 1; p[j] <= d[i]; j++)
if (is_prime(i * 100 + p[j]))
a[++t] = i * 100 + p[j];
for (int i = 4; i <= 9999; i += 4)
if ((i % 100 || !(i % 400)) && is_prime(i * 10000 + 229))
ans[++tot] = i * 10000 + 229;
for (int i = 1; i <= 9999; i++)
for (int j = 1; j <= t; j++)
if (is_prime(i * 10000 + a[j]))
ans[++tot] = i * 10000 + a[j];
cin >> T;
while (T--) {
cin >> (s + 1);
int cnt = 0;
for (int i = 1; i <= tot; i++) {
int now = ans[i], flag = 1;
for (int j = 8; flag && j; j--, now /= 10)
if (s[j] != '-' && s[j] - '0' != now % 10)
flag = 0;
cnt += flag;
}
cout << cnt << endl;
}
return 0;
}
标签:mes space return cout 知识 out lock 奇迹 mat
原文地址:https://www.cnblogs.com/xht37/p/11107871.html