It'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.
Author: ZHOU, Yuchen
Source: The 11th Zhejiang Provincial Collegiate Programming Contest
思路:简单题,一开始没注意数据的访问,各种超,以后做数学题还是要注意找规律,循环节是294,打个表看一下就行了 打表+快速幂
AC代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;
#define MOD 7
#define LL long long
const int n=300;
int aa[n];
string ss[]={"Saturday","Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday"};
LL powerMod(LL n){
LL tmp=n;
LL ans=1;
while(tmp){
if(tmp%2) ans=(ans*n)%MOD;
tmp/=2;
n=(n*n)%MOD;
}
return ans;
}
int main(){
int t;
int ans=0;
for(int i=1;i<=n;i++){
ans+=powerMod(i);
aa[i]=ans%MOD;
}
scanf("%d",&t);
while(t--){
int nn;
scanf("%d",&nn);
nn%=294;
//cout<<aa[nn]<<endl;
cout<<ss[aa[nn]]<<endl;
}
return 0;
}