题目描述
如果把一年之中的某个时间写作 a 月 b 日 c 时 d 分 e 秒的形式,当这五个数都为质数时,我们把这样的时间叫做质数时间,现已知起始时刻是 2022 年的 a 月 b 日 c 时 d 分 e 秒,终止时刻是 2022 年的 u 月 v 日 w 时 x 分 y 秒,请你统计在这段时间中有多少个质数时间?
输入
输入共 (2∗T+1) 行。第一行一个整数 T ,代表共有 T 组查询。
接下来2∗T 行,对于每组查询,先输入一行五个整数a、b、c、d、e ,代表起始时刻是 a 月 b 日 c 时 d 分 e 秒。再输入一行五个整数u、v、w、x、y,代表终止时刻是 u 月 v 日 w 时 x 分 y 秒。
对于每组查询保证输入的起始时刻不晚于终止时刻。输出
输出共 T 行,一行一个整数,表示对于每组查询输入统计到的从 a 月 b 日 c 时 d 分 e 秒到 u 月 v 日 w 时 x 分 y 秒中质数时间的个数。多组查询结果用换行分隔。
样例输入
复制
3 3 3 3 3 0 3 3 3 5 59 7 2 6 45 32 7 29 15 30 54 2 6 2 45 32 12 3 16 56 8
样例输出
复制
34 24276 127449
提示
对于所有数据,保证1≤T≤10^5 且1≤a,u≤12, 1≤b, 1≤b,v≤31, 0≤c,w<24, 0≤d,x<60 ,0≤e,y<60。
我的午饭!。。。。
好吧就是预处理暴力,是谁在递归写时间进制是谁啊
代码
#include<bits/stdc++.h>
using namespace std;
const int N=3.2e7;
int t;
int k[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
vector<int>who(N,0);
vector<int>prim;
void creat(){for(int i=2;i<=60;++i){int f=0;for(int j=2;j<=sqrt(i);++j){if(i%j==0){f=1;break;}}if(!f)prim.push_back(i);}
}int time(int y,int d,int h,int m,int s){int x=d;for(int i=1;i<y;++i)x+=k[i];return ((x*24+h)*60+m)*60+s;
}void jab(){int month[]{2,3,5,7,11};int day[]{2,3,5,7,11,13,17,19,23,29,31};int hour[]{2,3,5,7,11,13,17,19,23};for(auto a:month){for(int b=0;b<11&&day[b]<=k[a];++b){for(auto c:hour){for(auto d:prim)for(auto e:prim)who[time(a,day[b],c,d,e)]++;}}}for(int i=1;i<N;++i)who[i]+=who[i-1];
}int main()
{ios::sync_with_stdio();cin.tie(nullptr);cout.tie(nullptr);cin>>t;creat();jab();while(t--){int a[6],b[6];for(int i=0;i<5;++i)cin>>a[i];for(int i=0;i<5;++i)cin>>b[i];int x=time(a[0],a[1],a[2],a[3],a[4]);int y=time(b[0],b[1],b[2],b[3],b[4]);cout<<who[y]-(x>0?who[x-1]:0)<<'\n'; }return 0;
}