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.
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272
这题很难找到规律(294太大了),但是用KMP里的next数组就可以很快找到。
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define ll long long
using namespace std;
long mod(long a,long n,long b){ //a^b mod c
long t;
if(n==0) return 1%b;
if(n==1) return a%b;
t=mod(a,n/2,b);
t=t*t%b;
if((n&1)==1) t=t*a%b;
return t;}
int main(){
string s[7]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
ll x[1005];
x[0]=0;
for(int i=1;i<=294;++i)
x[i]=(x[i-1]%7+mod(i,i,7))%7;
// ll x[1005];
// x[0]=0;
// for(int i=1;i<=1000;++i)
// x[i]=(x[i-1]%7+mod(i,i,7))%7;
// int next[1001];0
// next[0] = 0;
// int len=1000;
// for(int i = 1, q = 0; i < len; i++){ //x[]里放的是要找规律的数组
// while(q > 0 && x[i] != x[q])
// q = next[q-1];
// if (x[i] == x[q])
// q++;
// next[i] = q;
// if (q != 0 && (i + 1) % (i + 1 - q) == 0){
// printf("%d\n", i+1-q); //输出的就是最大循环长度
// break;
// }
// }
int t;
cin>>t;
while(t--){
int a;
cin>>a;
cout<<s[x[a%294]]<<endl;
}
return 0;
}