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.
题意:假设今天是星期六,然后给你一个数n,问你1的一次方+2的平方+3的3次方....+n的n次方天后是星期几。
思路:
一开始稍微挨着看了看,发现没什么规律,就去想别的找规律的方法去了,结果打表就可以。
打表就没有什么好说的了,结束之后打了表一看,循环节是294,这东西单凭找是找不出来的,需要一个你的直觉吧算是,你认定必定有循环节,便直接打表看看就得出来了。
想想其实很多题就是打表来过的,以后也得有这种意识啊。像这种题一看就是有规律的,但是上来方向有点偏,所以一直也没有做出来。如果一开始认定有循环节直接打一下表的话,很快就出来了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=1e5+7;
const int inf=1e9;
int n,m;
int pw(int a,int b)
{
int base=a%7;
int sum=1;
while(b)
{
if(b&1)sum=(sum*base)%7;
base=(base*base)%7;
b>>=1;
}
return sum%7;
}
char ans[7][20]= {"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
int num[1001];
int main()
{
int i;
int t;
int sum=0;
for(i=0; i<294; ++i)
{
sum+=pw(i+1,i+1);
num[i]=sum%7;
}
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
n--;
printf("%s\n",ans[num[n%294]]);
}
return 0;
}