It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days?
There are multiple test cases. The first line of input contains an integer Tindicating the number of test cases. For each test case:
There is only one line containing one integer N (1 <= N <= 1000000000).
For each test case, output one string indicating the day of week.
2 1 2
Sunday Thursday
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
写一发快速幂进行打表操作,先打1-1000之间的,然后找规律,发现每294个数循环一遍。
所以只保存294个数的就可以了,其他数值需要对他取模操作就OK了。
注意快速幂函数中要将每一位的平方%7.。不然会存不下的。。还有存放星期的数组用string会超时。。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAX_N 100005
#define INF 0x3f3f3f3f
#define Mem(a,x) memset(a,x,sizeof(a))
#define ll long long
char week[10][15] = {"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
ll ans[1005] = {
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,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 };
//ll quipow(ll num,ll n) {
//
// ll res = 1;
// while(n > 0) {
// if(n & 1) res *= num;
// num *= num;
// num %= 7;
// n >>= 1;
// }
// return (res%7);
//}
int main()
{
// ll sum = 0;
// for(ll i = 1; i<=1000; i++) {
// sum += quipow(i,i);
// sum %= 7;
// ans[i] = sum;
// }
//
//
for(ll i = 1; i<=1000; i++) {
cout<<i<<' '<<ans[i]<<" ";
if(i%10 == 0) cout<<endl;
}
// for(ll i = 1; i<=295; i++) {
// cout<<ans[i]<<",";
// }
int k;
cin>>k;
while(k--) {
ll n;
scanf("%lld",&n);
int tmp = ans[n%294];
printf("%s\n",week[tmp]);
}
return 0;
}