What day is that day? ZOJ - 3785

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 Tindicating 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.


题意:假设今天是星期六,然后给你一个数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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值