1. 程式人生 > >What day is that day? ZOJ

What day is that day? ZOJ

What day is that day?

It's Saturday today, what day is it after 11 + 22 + 33 + ... + NNdays?

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.

找規律題的一種技巧

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;


#define ll long long
const int N = 1e6 + 7;
const int M = 500;
const int mod = 7;

ll ksm(ll a, ll b, ll c) {
	ll ans = 1;
	a %= c;
	while (b > 0) {
		if (b&1) ans = (ans * a) % c;
		a = a*a%c;
		b>>=1;
	}
	return ans;
}

int sum[N];
int next_[N];

void print(int op) {
	if (op == 1) {
		puts("Monday");
	} else if ( op == 2) {
		puts("Tuesday");
	} else if (op == 3) {
		puts("Wednesday");
	} else if (op == 4) {
		puts("Thursday");
	} else if (op == 5) {
		puts("Friday");
	} else if (op == 6) {
		puts("Saturday");
	} else {
		puts("Sunday");
	}
}

void get_next(int len) {
	
	int i = 0, j = -1;
	next_[0] = -1;
	while (i <= len) {
		if (j == -1 || sum[i] == sum[j]) {
			++i, ++j;
			next_[i] = j;
		} else j = next_[j];
	}
	
}





int main() {
	
	sum[0] = 5;//因為是模7所以星期六是5、星期五是4... 
	for (int i = 1; i <= M; ++i) {
		sum[i] = (ksm(i, i, mod) + sum[i-1]) % mod;
	}
	//printf ("%d\n", sum[294]); // 5
	//get_next(M);
	
	
	int t;
	scanf ("%d", &t);
	while (t--) {
		
		int n;
		scanf ("%d", &n);
		print(sum[n%294]+1);
		//getchar();
		//暴力法找迴圈節 
//		for (int i = 1; i <= n; ++i) {
//			int ok = 1;
//			for (int j = 1; j <= i; ++j) {
//				if (sum[j] != sum[i+j]) {
//					ok=0;
//					break;
//				}
//			}
//			if (ok) {
//				printf ("%d\n", i);
//				break;
//			}
//		}
		// kmp的next找迴圈節 
		//for (int i =1; i <= n; ++i) {
			//printf ("%d\n", sum[i]);
			//printf ("%d\n", next_[i]);
		//	int len = i - next_[i];
		//	if (len!=i && i%len == 0 ) {
		//		printf ("%d %d\n", i, i/len);
		//		break;
		//	}
		//}
	//	puts("over");
	}
	
	
	
	
	
	
	return 0;
}

相關推薦

What day is that day? ZOJ

What day is that day? It's Saturday today, what day is it after 11 + 22 + 33 + ... + NNdays? Input There are multiple test cases. The

What day is that day?(zoj水題)

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 Ther

HDU 1308 What Day Is It?(模擬,日期)

else 天數 pre names 一點 val return can 星期幾 解題報告:輸入一個年月日,讓你求出那一天是星期幾,但是做這題之前必須先了解一點歷史。首先在1582年之前,判斷是否是閏年的標準是只要能被四整除就是閏年, 然後在1752年9月2號的後的11天被

知道年月日就可以計算那一天是星期幾(What day is today?)

公式 W =〔 [c/4] - 2c + y + [y/4] + [13 * (m+1) / 5] + d - 1 〕% 7 (或者是:w= 〔y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1 〕% 7) 若要計算的日期是在1582年10月4日或之前,公式

7 years ago is the day the + operator went away | Hacker News

On that day we lost an operator. Google flipped a bit, + became a noop, and things have been odd ever since.But like a perfect code in perfect parity, a st

【Caius的部落格】A day does not come again, one day is difficult. In time to encourage, time does not wait for people.

A day does not come again, one day is difficult. In time to encourage, time does not wait for people...

The truth is what it is, not what you see

moc rac 安排 and ace tin start 工作 tel 今天在知乎看到一個回答,很有感觸,遂記錄拷貝在此: 不要在年齡方面焦慮,復制一段話給你看 紐約時間比加州時間早三個小時, New York is 3 hours ahead of California,

EJB,What's that

EJB是sun的JavaEE伺服器端元件模型,設計目標與核心應用是部署分散式應用程式。簡單來說就是把已經編寫好的程式(即:類)打包放在伺服器上執行。憑藉java跨平臺的優勢,用EJB技術部署的分散式系統可以不限於特定的平臺。EJB (Enterprise JavaBean)是J2EE(

2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)

What time is it anyway?  524288K   The \text{Frobozz Magic Clock Company}Frobozz Magic Clock Company makes

2018 ICPC Greater New York Regional Contest E What time is it anyway?(暴搜)

family 輸入 trigger 可能 hit open 這不 card enter What time is it anyway? 524288K The \text{Frobozz Magic Clock Company}Frobozz Magic Clo

English trip V1 - 11.What's That? 那是什麽?Teacher:Patrick Key:There's/There are

lesson 對象 如何 his clas 詞匯 bsp english rip In this lesson you will learn to describe the position of an object. 在本課中,您將學習如何描述對象的位置。 課上內容(

What Exactly Is Cancer Immunotherapy?

Cancer immunotherapy is in the spotlight this week after two scientists won the Nobel Prize on Monday for their contributions to the treatment.The 2018 Nob

An introduction to Generative Art: what it is, and how you make it

An introduction to Generative Art: what it is, and how you make itMandelbrot’s Fractal is derived from a deceptively simple equationGenerative art can be a

What exactly is an A.I. Model? An ELi5.

What exactly is an A.I. Model? An ELi5.Machine Learning Models. We hear about them all the time. They look and sound awesome, but can they predict and reac

What else is hidden in the 2018.3 EAP 1?

Three days ago we announced that we are opening up our Early Access Program for the upcoming GoLand 2018.3 release. We have added such an enor

A3C — What It Is & What I Built

The 3 A’s of A3CActor-CriticThe basic actor-critic model stems from Deep Convolution Q-Learning which is where the agent implements q-learning, but instead

So what exactly is Vlad’s Sharding PoC doing?

So what exactly is Vlad’s Sharding PoC doing?I had a chance to work with Vlad Zamfir and Aditya Asgaonkar on the continuation of Vlad’s Berlin hack this we

A quick intro to Dependency Injection: what it is, and when to use it

Why should I use dependency injection?Let’s say we have a car class which contains various objects such as wheels, engine, etc.Without dependency injection

I'm starting an affiliate program for my small app, is that dumb?

Hey ya'll,I thought of kicking off an affiliate program for a small app of mine which does around 1 sale every 10 visits.I thought that was pretty good con

I Don’t Know Python Yet, But Is That a Reason Not to Hire Me?

At the interview for a fourth position, I had my dream opportunity: I sat in front of the head of development, support, and QA as a support candidate. Fina