What day is that day?
Time Limit: 2 Seconds Memory Limit: 65536 KB
It’s Saturday today, what day is it after $1^1 + 2^2 + 3^3 + … + N^N$ 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
1 | 2 |
Sample Output
1 | Sunday |
Hint
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
Solve
对于$1 \dots N$,对于$7$取模后,可以转换成一大串$0 \dots 6$的循环,所以$1^1 + 2^2 + 3^3 + … + N^N$可以转换成:$1^1+2^2+3^3+ \dots (N\%7)^N$,然后我们可以发现,这个式子的值是七个等比数列的前$x$项和的总和。每项公比为$num^7$,第一项为$n^n$$(0\leq n \leq 6)$
那么我们只需要统计出$0\dots 6$的个数,并利用等比数列的前$n$项和公式计算即可
~百度了一下,发现似乎写麻烦了,貌似可以直接打表找规律?而且代码还特别短,想看短代码的自行百度吧,貌似没有找到我这种方法写的QAQ~
Code
1 | /************************************************************************* |