Zoj 3785 What day is that day?

来源:互联网 发布:淘宝新店铺买流量 编辑:程序博客网 时间:2024/05/06 20:27
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

212

Sample Output

SundayThursday

Hint

A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.


Author: ZHOU, Yuchen

Source: The 11th Zhejiang Provincial Collegiate Programming Contest

  

  思路:简单题,一开始没注意数据的访问,各种超,以后做数学题还是要注意找规律,循环节是294,打个表看一下就行了   打表+快速幂

  AC代码如下:

#include <iostream>#include <cstring>#include <cstdio>#include <string>using namespace std;#define MOD 7#define LL long longconst int n=300;int aa[n];string ss[]={"Saturday","Sunday","Monday","Tuesday","Wednesday",                "Thursday","Friday"};LL powerMod(LL n){    LL tmp=n;    LL ans=1;    while(tmp){        if(tmp%2) ans=(ans*n)%MOD;        tmp/=2;        n=(n*n)%MOD;    }    return ans;}int main(){    int t;    int ans=0;    for(int i=1;i<=n;i++){        ans+=powerMod(i);       aa[i]=ans%MOD;    }    scanf("%d",&t);    while(t--){        int nn;        scanf("%d",&nn);        nn%=294;        //cout<<aa[nn]<<endl;        cout<<ss[aa[nn]]<<endl;    }    return 0;}



0 0
原创粉丝点击