ZOJ 3785 What day is that day?【思维+递推循环节】

What day is that day? Time Limit: 2 Seconds       Memory Limit: 65536 KB

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


题目大意:给你一个公式,让你求6+公式和==星期几、


思路:一看这么大的一个N,要么是跟矩阵快速幂有关,要么是跟找规律有关,不过这个题的公式很容易让人想到的是去找规律,所以在模拟训练的时候我和队长的思路都是去找规律,同时也是去找循环节。


我们暴力打出数据,然后找到循环节是294.然后求N%294的时候的结果就可以了,注意一个点,如果%294==0的时候,我们要特殊判定一下。

AC代码:

#include<stdio.h>
#include<string.h>
using namespace std;
#define mod 7
#define ll long long int
ll qmi(ll a,ll b)
{
    a%=mod;
    ll ans=1;
    while(b)
    {
        if(b%2==1)ans=(ans*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return ans;
}
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            int n;
            scanf("%d",&n);
            if(n%294==0)
            {
                printf("Saturday\n");
            }
            else
            {
                ll sum=0;
                n%=294;
                for(int i=1;i<=n;i++)
                {
                    sum=(sum+qmi(i,i))%7;
                }
                sum=(sum+6)%7;
                if(sum==0)printf("Sunday\n");
                if(sum==1)printf("Monday\n");
                if(sum==2)printf("Tuesday\n");
                if(sum==3)printf("Wednesday\n");
                if(sum==4)printf("Thursday\n");
                if(sum==5)printf("Friday\n");
                if(sum==6)printf("Saturday\n");
            }
        }
    }
}







你可能感兴趣的:(ZOJ,3785)