Time Limit: 2 Seconds Memory Limit: 65536 KB
题目
t’s Saturday today, what day is it after 11 + 22 + 33 + … + NN days?
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
There is only one line containing one integer N (1 <= N <= 1000000000).
Output
For each test case, output one string indicating the day of week.
Sample Input
2
1
2
Sample Output
Sunday
Thursday
Hint
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
我的思路:
打表的方法,先输出前700个求(11 + 22 + 33 + … + NN )%7之后的余数,找到规律,然后,看一下从哪里开始重复(虽然数多了一些,但是还能找到的),就能找到规律了!
之前写的话,想用快速幂来求,可是数字大,最后还是超时了,最后找出来规律就可以更简单的做了,还不担心超时。
我的代码
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[300]={0,4,3,0,3,4,4,5,6,3,5,6,5,5,6,1,6,0,5,6,6,0,4,5,2,6,5,5,6,0,3,5,4,5,5,6,1,3,4,6,
5,5,6,3,2,6,2,3,3,4,5,2,4,5,4,4,5,0,5,6,4,5,5,6,3,4,1,5,4,4,5,6,2,4,3,4,4,5,0,2,
3,5,4,4,5,2,1,5,1,2,2,3,4,1,3,4,3,3,4,6,4,5,3,4,4,5,2,3,0,4,3,3,4,5,1,3,2,3,3,4,
6,1,2,4,3,3,4,1,0,4,0,1,1,2,3,0,2,3,2,2,3,5,3,4,2,3,3,4,1,2,6,3,2,2,3,4,0,2,1,2,
2,3,5,0,1,3,2,2,3,0,6,3,6,0,0,1,2,6,1,2,1,1,2,4,2,3,1,2,2,3,0,1,5,2,1,1,2,3,6,1,
0,1,1,2,4,6,0,2,1,1,2,6,5,2,5,6,6,0,1,5,0,1,0,0,1,3,1,2,0,1,1,2,6,0,4,1,0,0,1,2,
5,0,6,0,0,1,3,5,6,1,0,0,1,5,4,1,4,5,5,6,0,4,6,0,6,6,0,2,0,1,6,0,0,1,5,6,3,0,6,6,
0,1,4,6,5,6,6,0,2,4,5,0,6,6};
ll day = 0;
int main()
{
int T;
ll num, temp;
scanf("%d",&T);
while(T--) {
scanf("%lld",&num);
temp = a[(num-1) % 294];
if (temp == 0) {
printf("Sunday\n");
}
if (temp == 1) {
printf("Monday\n");
}
if (temp == 2) {
printf("Tuesday\n");
}
if (temp == 3) {
printf("Wednesday\n");
}
if (temp == 4) {
printf("Thursday\n");
}
if (temp == 5) {
printf("Friday\n");
}
if (temp == 6) {
printf("Saturday\n");
}
}
}