ZOJ3785-What day is that day?

来源:互联网 发布:js给集合添加元素 编辑:程序博客网 时间:2024/06/06 16:25

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


题意:给你一个n,今天星期六,问11 + 22 + 33 + ... + NN 天后是星期几

解题思路:打表后找到循环节


#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <map>#include <vector>#include <queue>#include <bitset>#include <stack>using namespace std;int a[1005];int qpow(int x,int y){    int sum=1;    while(y)    {        if(y&1) sum*=x,sum%=7;        y>>=1;        x*=x;        x%=7;    }    return sum;}int main(){    a[1]=1;    for(int i=2;i<=400;i++)    {        int k=i%7;        int ans=qpow(k,i);        a[i]=ans+a[i-1];        a[i]%=7;    }    a[0]=a[294];    int n,t;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        n%=294;        if(a[n]==0) printf("Saturday\n");        else if(a[n]==1) printf("Sunday\n");        else if(a[n]==2) printf("Monday\n");        else if(a[n]==3) printf("Tuesday\n");        else if(a[n]==4) printf("Wednesday\n");        else if(a[n]==5) printf("Thursday\n");        else if(a[n]==6) printf("Friday\n");    }    return 0;}

0 0
原创粉丝点击