ZOJ 3326 An Awful Problem 模拟

只有在 Month 和 Day 都为素数的时候才能得到糖

那就模拟一遍时间即可.

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; int month1[] = {, , , , , , , , , , , , };
int month2[] = {, , , , , , , , , , , , }; bool run (int x) {
if (x % == && x % != || x % == ) return true;
return false;
} bool prime (int num){
if (num == ) return false;
for (int i = ; i <= sqrt(num); ++i){
if (num % i == ) return false;
}
return true;
} int main() {
std::ios::sync_with_stdio(false);
int i, j, t, k, u, v, numCase = ;
int y1, y2, m1, m2, d1, d2;
cin >> t;
while (t--) {
cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
int ans = ;
while (y1 < y2) {
if (!run (y1)){
for (; m1 <= ; ++m1) {
for (; d1 <= month1[m1]; ++d1){
if (prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
} else{
for (; m1 <= ; ++m1) {
for (; d1 <= month2[m1]; ++d1) {
if (prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
}
m1 = ;
++y1;
}
if (!run (y1)) {
for (; m1 < m2; ++m1) {
for (; d1 <= month1[m1]; ++d1) {
if (prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
for (; d1 <= d2; ++d1) {
if (prime(m2) && prime(d1)) ++ans;
}
} else{
for (; m1 < m2; ++m1) {
for (; d1 <= month2[m1]; ++d1) {
if(prime(m1) && prime(d1)) ++ans;
}
d1 = ;
}
for (; d1 <= d2; ++d1) {
if(prime(m2) && prime(d1)) ++ans;
}
}
cout << ans << endl;
} return ;
}
上一篇:盒子模型、网页自动居中、float浮动与清除、横向两列布局


下一篇:Linux运行Java出现“Exception in thread "main" java.lang.OutOfMemoryError: Java heap space”报错