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

23 篇文章 0 订阅

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");
            }
        }
    }
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值