程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ZOJ3785:What day is that day?

ZOJ3785:What day is that day?

編輯:C++入門知識

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.

通過打表發現周期是294,那麼就簡單了

#include 
#include 
#include 
using namespace std;

char day[10][10] = {"Saturday","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
int s[300];

int work(int n)
{
    int sum = 1,i;
    for(i = 1;i<=n;i++)
    {
        sum = sum*n;
        sum%=7;
    }
    return sum;
}

int main()
{
    int t,n,i,j,len;
    s[0] = 0;
    for(i = 1;i<=294;i++)
    {
        s[i] = s[i-1]+work(i);
        s[i]%=7;
    }
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        n%=294;
        printf("%s\n",day[s[n]]);
    }


    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved